Hi,
In the Before Update event of a text box I put this procedure, such that the user would get a message if he tries to enter a duplicate entry.
Private Sub Tool_BeforeUpdate(Cancel As Integer)
If DCount("[Tool]", "Tools Table", "[Tool]='" & Me.Tool & "'") Then
MsgBox "This Tool already exists." & _
vbCrLf & "Sorry but this would create a duplicate Entry.", _
vbOKOnly, "Duplicate Entry"
Cancel = True
Me.Undo
Exit Sub
Else 'Do nothing
End If
End Sub
This works fine, hovever, the Auto Number (primary key) would still increment, even though nothing is written to the table. Is the problem something with the procedure or anything else?
Thanks for your help,
Mike.
In the Before Update event of a text box I put this procedure, such that the user would get a message if he tries to enter a duplicate entry.
Private Sub Tool_BeforeUpdate(Cancel As Integer)
If DCount("[Tool]", "Tools Table", "[Tool]='" & Me.Tool & "'") Then
MsgBox "This Tool already exists." & _
vbCrLf & "Sorry but this would create a duplicate Entry.", _
vbOKOnly, "Duplicate Entry"
Cancel = True
Me.Undo
Exit Sub
Else 'Do nothing
End If
End Sub
This works fine, hovever, the Auto Number (primary key) would still increment, even though nothing is written to the table. Is the problem something with the procedure or anything else?
Thanks for your help,
Mike.