Notify when field entry has same data

M

Mike

Is it possible to have a message box or something similar appear when a
duplicate entry is made in a field? I still want to be able to enter the
duplicate data but I would like to know when it happens.
 
W

Wayne-I-M

Hi Mike

You need to refer to the primary field of the record – in the code below
this is FieldID (change the field name to what you want)

Say you wanted to be warned if they same 1st name and surname was entered –
remember though there are many John Smiths - so it’s just a warning.


Private Sub SurnameField_AfterUpdate()
If ((DLookup("[FieldID]", "[TableName]", "[1stNameField] ='" &
Form!1stNameFielde & "' AND [SurnameField] = '" & Form!SurnameField & "'")))
Then
Beep
MsgBox "Some message", vbOKOnly, "Message box title"
End If
End Sub

Of course this is on the AfterUpdate of the SurnameField and there are
zillions of Johns -
If it’s just a single field you are checking then simply remove the AND
section
 
Top