duplicate values

  • Thread starter Thread starter Tim Richardson
  • Start date Start date
T

Tim Richardson

I want to keep a user from keying in a duplicate key field
in a record. (like Social Security #). I can make it a
key field, but the problem is that I do not want access to
dislplay an error message. I would like to display a more
user-friendly message, and cancel the changes.

any suggestions?

Thanks

Tim
 
I've done this a couple of different places.

Let's assume you have a TextBox for the SSN. In the
LostFocus or BeforeUpdate event for the TextBox, you can
use a DCount function (check the Help files for specifics)
to see if the number has already been entered into the
database and display your message if it hasn't:

Dim strSSN as String
Dim i as Integer

strSSN = [txtSSN]
i = DCount("[SSN]","tblEmployees","[SSN]='" & strSSN & "'")

If i > 0 Then
MsgBox "Enter your kinder message here"
End If

Remember, Access will not include the record you're
entering in the lookups until you've finished entering it
(ie gone to a new record). Also, I've included other
lookups with the error messages to display the data
already entered (employee name, etc.)

Hope this helps!

Howard Brody
 
I've done this a couple of different places.

Let's assume you have a TextBox for the SSN. In the
LostFocus or BeforeUpdate event for the TextBox, you can
use a DCount function (check the Help files for specifics)
to see if the number has already been entered into the
database and display your message if it hasn't:

Dim strSSN as String
Dim i as Integer

strSSN = [txtSSN]
i = DCount("[SSN]","tblEmployees","[SSN]='" & strSSN & "'")

If i > 0 Then
MsgBox "Enter your kinder message here"
End If

Remember, Access will not include the record you're
entering in the lookups until you've finished entering it
(ie gone to a new record). Also, I've included other
lookups with the error messages to display the data
already entered (employee name, etc.)

Hope this helps!

Howard Brody
 
Back
Top