Check for Duplicates

C

Christina

I have a field that I have set as "No Duplicates" in the table view. But it only tells me if a duplicate is entered after I fill out the rest of the form and save it. I would like to set it so that "On Exit" it checks for duplicates and prompts the user that it isn't allowed because of duplicates. If anyone can help me that would be great
Thank
Christina
 
R

Rick Brandt

Christina said:
I have a field that I have set as "No Duplicates" in the table view. But
it only tells me if a duplicate is entered after I fill out the rest of the
form and save it. I would like to set it so that "On Exit" it checks for
duplicates and prompts the user that it isn't allowed because of
duplicates. If anyone can help me that would be great!
Thanks
Christina

BeforeUpdate would be better. Example below assumes a Text field. For a
numeric field you would remove the single quotes.



If DCount("*", "YourTableName","YourFieldName = '" & Me!YourFieldName &
"'") > 0 Then
MsgBox "Duplicate Value"
Cancel = True
End If
 
C

Christina

This is the code I used, but it's coming up with an error in the first line. Do you see anything wrong with this
Thank

If DCount("*", "Client_Info", "Client_Number = '" & Me!Client_Number & "'") > 0 The
MsgBox "Duplicate Client Number
Cancel = Tru
End If
 

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

Top