duplicate entries

L

Lauren B

I have a database where users are inputing customers who are identified by a
unique Customer_ID (this is the primary key). If a user attempts to enter a
primary key that is already in use, they will get the following message
after completing the entire form and attempting to save the entry:

"The changes you requested to the table were not successful because they
would create duplicate values in the index, primary key, or relationship.
Change the data in the field or fields that contain duplicate data, remove
the index, or redefine the index to permit duplicate entries and try again."

Is there a way to code the form (perhaps in the after update property of the
Customer_ID text box "TxtCustomer_ID") so that when a user enters a
Customer_ID that is already in use, a message box will appear immediately
(as opposed to after the user already completes the entire form) that reads
something like "Customer ID already in use, please select a new name."

Thank you in advance for any assistance.

LB
 
G

Guest

hi,
yes. in the before update event of the cust id text box
put something like this
if dlookup("[cust_ID]","yourtable", "cust_ID = '"&
Me.txtcustID &"'" then
msgbox "Customer ID already in use, please select a new
name."
exit sub
end if
this will alert and kill code execution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top