Capture Duplicate Key After Update of Text Box Instead of Form

M

Michael

Hi Folks - Currently, I am using the Error Event of my form to capture
duplicate key entry. However, this is not invoked until the form updates. Is
there a way to check for a duplicate after the user tabs out of the primary
key field? Thanks.
 
K

Klatuu

Use the Before Update event of the primary key field to look for an exiting
entry. If it is found, you can present a warning an cancel the event:

Private Sub PrimaryField_BeforeUpdate(Cancel As Integer)

If Not IsNull(DLookup("[PrimaryKeyFieldName]", "TableName",
"[PrimaryKeyFieldName] = " & Me.PrimaryField)) Then
MsgBox "Duplicate Entry Found"
Cancel = True
End If
 
J

Jeff Boyce

Michael

Already answered in one of the other newsgroups you posted this (separately)
to. If you post repeatedly, none of the posts (and none of the responses)
are connected, so you waste your time/energy looking through all the places
you posted, and the time/energy of the folks who volunteer here.

If you must post to more than one group (hint: rarely necessary), select the
multiple groups in the "To:" section, rather than posting separately.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Top