|
-
Apr 19th, 2007, 08:57 AM
#1
Thread Starter
Fanatic Member
unique values for non must field
Hi,
I've got an ms access table with customers details. some customers ask to make a customer card for them and then they get a customer card no. so card_no is not a compulsory field. however, I'd like to make sure that this field can never have duplicate values.
any ideas how ?
-
Apr 19th, 2007, 09:02 AM
#2
Re: unique values for non must field
Since null is allowed in the field I would normally try and get a count from the database where the card_no is equal to the value you want too input. If the count comes back > 0 then the number is already in use.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Apr 19th, 2007, 09:09 AM
#3
Thread Starter
Fanatic Member
Re: unique values for non must field
so you are talking about a solution in the interface, in each place where the card no can be modified.
1. isn't there a way to do in the database.
2. how do I make sure that all updates to this field will pass through this check? (there are many places where it can be modified)
thanks,
-
Apr 19th, 2007, 09:14 AM
#4
Re: unique values for non must field
Yes, you can do something in the database and that is set the field up to not allow duplicates.
However, there still MUST be code in your interface as well. That code would have to deal with the error that would be generated by the database if a duplicate number was attempted to be entered. Each place in your code where something can be written to this field would have to have the code that dealt with the potential of this error.
-
Apr 19th, 2007, 09:16 AM
#5
Re: unique values for non must field
Create a function and call the function. If nulls are allowed you can't depend on the DB to control this (only one null will be allowed). Another option could be to create a table in the DB that hold nothing but a number. This table holds one row just long integer value. When you want to create a new card_no you select the number from this table, then increment the number by 1 and now create the new card_no with that returned number.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Apr 19th, 2007, 09:23 AM
#6
Thread Starter
Fanatic Member
Re: unique values for non must field
card numbers should also be allowed to be modified manually, and not only automatically (otherwise it would very easy to handle)
-
Apr 19th, 2007, 09:25 AM
#7
Re: unique values for non must field
Modified manually how?
How does this manual modification impact what you are writing?
-
Apr 19th, 2007, 09:38 AM
#8
Re: unique values for non must field
Then you are back to checking the count of card_no each time you do something.
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|