I've looked at the below question which is exactly what I am trying to do, however the posted answer doesn't seem to work for me. My query is essentially the same, but I will elaborate.
I have a form which updates a table of information with the following:
Forename
Surname
EmailAddress
The database also adds DateEntered automatically via the =Date() in the default value setting of the field, and there is a primary key auto number called CPDEAID.
I added the following code to the form.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Set rst = Me.RecordsetClone
rst.FindFirst "[CPDEAID] <> " & Me.CPDEAID & " AND [Forename] = " & Me.Forename & " AND [Surname] = " & Me.Surname & " AND [EmailAddress] = " & Me.EmailAddress
If Not rst.NoMatch Then
Cancel = True
If MsgBox("This person already exists; would you like to go to the existing record?", vbYesNo) = vbYes Then
Me.Undo
DoCmd.SearchForRecord , , acFirst, "[CPDEAID] = " & rst("CPDEAID")
End If
End If
rst.Close
End Sub
However, this doesn't seem to work. The only way that I can get my database to not create the duplicate record is via creating a multi-column index - but this is a little messy as I want a clean "user-friendly" front end.
Am I missing something very simple here?
Prevent Duplicate Records, Query Before Creating New Records