Hi all, I'm trying to prevent duplicate entries in a field with a DCount and custom message box, but the code isn't quite right... keep getting Syntax Error (missing operator) in query expression '[CommentAlarm]='
Also, if I prevent duplicate entries in this way do i still need the table field set to index no duplicates or can i have no index and this will prevent duplicates for me? (As long as this is the only entry for this field obviously). Cheers
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblCustomerComments", "[CommentAlarm]=" & Me.txtCommentAlarm) > 0 Then ' It is a duplicate
Cancel = True
MsgBox "Sorry an alarm has already been set at this Date/Time, please enter a different Date/Time"
Me.Undo '<----Remove this if you don't want to erase form input
End If
End Sub
Also, if I prevent duplicate entries in this way do i still need the table field set to index no duplicates or can i have no index and this will prevent duplicates for me? (As long as this is the only entry for this field obviously). Cheers