What is the best way to check whether the value is in the table

  • Thread starter Thread starter Boon
  • Start date Start date
B

Boon

I have a table Customer. In table Customer, there is a field "ID".

The user will open a form and input a new ID, the VBA will then search
through the table Customer to check whether this new ID is already in the
table.
I use Dlookup, and if it returns null then there is no value. Is this the
best way to do? Is there a better way?

thanks
 
Boon said:
I have a table Customer. In table Customer, there is a field "ID".

The user will open a form and input a new ID, the VBA will then search
through the table Customer to check whether this new ID is already in the
table.
I use Dlookup, and if it returns null then there is no value. Is this the
best way to do? Is there a better way?


I think that's as good a way as any, if you really need to
check for it. If the ID field in the table is used as a
unique index, Access will not save the duplicate ID record
with a trappable error.

But, if you want to check for a duplicate value as soon as
it's entered, the go ahead and use DLookup in the text box's
BeforeUpdate event.
 
Back
Top