Duplicate Record Error Check

K

Kirk P.

Can I check for duplicate records and display an error message immediately
after entry of a CustID number? I would think somthing like this in the
AfterUpdate event would do it, but no luck.

If DataErr = 3022 Then
MsgBox "Duplicates not allowed"
End If
 
K

Klatuu

This is typically done in the control's Before Update event:

If Not IsNull(DLookup("[CustID]", "CustomerTable", "[CustID] = " &
Me.txtCustID)) Then
MsgBox "Customer " & Me.txtCustID & " is already in the table"
Cancel = 0
End If
 
Top