By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,584 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,584 IT Pros & Developers. It's quick & easy.

NO duplicate entries

P: 5
Quick Question. I gotta a database with fields firstname, lastname, and hobby, etc. I dont want to allow duplicate entries for the name. For instance....no john smith twice....but there can be a repeated john. Well i created a multi-field index and that is fine....the problem is that my form is very long....there is lots of data to enter and the user could very well end up adding all this data then going to close it and find out it wont work. I want the user to know that it is a duplicate name right after they enter the first and last name. Can you help me with this. I tried to put
DoCmd.RunCommand acCmdSaveRecord
in the after update field for first and last name. But it is giving me a runtime error. Can anyone help me? I know my code must be wrong.
Thanks in advance
Mar 27 '06 #1
Share this Question
Share on Google+
1 Reply


100+
P: 135
Looks like you're using MS Access (You should give details such as program, language, code snippets if available etc. when posting a question) Try creating a Query:
Expand|Select|Wrap|Line Numbers
  1.  SELECT COUNT(*) FROM YourTable WHERE FirstName = Trim(txtFirstName.Text) AND LastName = trim(LastName) 
Then once the person exits the txtFirstName or txtLastName have your form run a Function that runs the Query and returns the number of records. (0 for none, meaning no match.) Then go through an IF THEN to give notice of a duplicate entry.
Mar 27 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.