Autonumber is probably the easiest way of ensuring a unique number, but
it
will almost ineveitably leave gaps in the numbering. My point is only
that
if you need to see the number, autonumber may not be the best choice.
Thanks Bruce
I was trying to figure out how I could get the program to let me know
when
I
was duplicating a unique customer number. I have to use unique customer
numbers in another part of the program which pulls multiple orders from
a
single customer down to a listbox.
:
If the number is to be seen you may want to use an incrementing number
such
as is described here:
http://www.rogersaccesslibrary.com/download3.asp?SampleName=AutonumberProblem.mdb
I decided to use the meaningless number idea.
Thanks
:
On Thu, 16 Mar 2006 13:45:27 -0800, Ron Weaver
Hi all
I need some code to insert into the validation box in a table. I
have
a
field in the Customer table: "CustomerNumber". This number
consists
of 5
letters and an optional 2 digits. While inputing an order, I would
like
this
code to tell me if I'm creating a duplicate and advise me to
create
another
number. I would also like the input process to go no farther until
something
is entered in the field. I set the "Required" property to "Yes ",
but
it
just
tabs right on by. Access 2003.
Thanks
You should probably use "belt and braces" here. Make the
CustomerNumber the Primary Key of the table, and you won't be able
to
enter duplicates by *any* means... but you'll also get user-hostile
error messages if you try.
To provide a friendlier interface, use the BeforeUpdate event of
the
textbox on the Form you're using to enter the data (and yes, you
must
use a Form; table datasheets are extremely limited in their
capabilities). Something like
Private Sub txtCustomerNumber_BeforeUpdate(Cancel as Integer)
If Not IsNull(DLookUp("[CustomerNumber]", "[Customer]", _
"[CustomerNumber] = '" & Me!txtCustomerNumber & "'") Then
MsgBox "This customer number already exists, try again",
vbOKOnly
Cancel = True
Me!txtCustomerNumber.Undo
End If
End Sub
Frankly, I'd suggest using an automatically assigned meaningless
number, rather than frustrating your users by making them enter
numbers at hazard and punishing them if they guess wrong!
John W. Vinson[MVP]