I've got a DLookUp on a form which prevents a user adding a name that's already in there. Each record also has an autonumber ID.
When a duplicate is found the user has to exit. However, I've noticed that because of the autonumber ID field a record is still created in the underlying table. This record is empty apart from the ID field. Can I prevent this?
This is my code
If Not IsNull(DLookup("[Organisation]", "tblOrganisations", "[Organisation]='" & Me![Organisation] & "'")) Then
MsgBox "That Organisation already exists. Return to Organisation Search and try again", vbCritical
Me.Organisation.Undo
Me.ID.Undo
Cancel = True
End If
End Sub
When a duplicate is found the user has to exit. However, I've noticed that because of the autonumber ID field a record is still created in the underlying table. This record is empty apart from the ID field. Can I prevent this?
This is my code
If Not IsNull(DLookup("[Organisation]", "tblOrganisations", "[Organisation]='" & Me![Organisation] & "'")) Then
MsgBox "That Organisation already exists. Return to Organisation Search and try again", vbCritical
Me.Organisation.Undo
Me.ID.Undo
Cancel = True
End If
End Sub