I have a text box in a data entry form bound to an NON-INDEXED field. I have put in codes to check for duplicates and to prevent input of duplicate data:
If (Eval("DLookup(""[TicketNo]"", ""[TS_Collect]"", ""[TicketNo] = FORM![TicketNo]"") Is Not Null")) Then
Beep
MsgBox "This ticket has been entered already. Please check your number." & Chr(10) & Chr(10) _
& "Or press [Esc] key to cancel input.", vbExclamation, "Double entry!"
DoCmd.CancelEvent
DoCmd.RunCommand acCmdUndo
End If
But I have 2 problems:
1. If a duplicate value is entered an MS Access message pops up following my message box says "The value in the field or record violates the validation rule for the record or field." with an example and explanation. Even though I have no validation rule set for the field. I don't know why it comes out and how to get rid of it.
2. After clicking OK to close the message box, I can enter a new value. But if I want to cancel data entry I need to press Esc twice. The first time I press Esc the value I just entered re-appears, I have to press Esc again to cancel the input of a new record. How can I cancel input with only one Esc key press?
Thanks.
Peter
If (Eval("DLookup(""[TicketNo]"", ""[TS_Collect]"", ""[TicketNo] = FORM![TicketNo]"") Is Not Null")) Then
Beep
MsgBox "This ticket has been entered already. Please check your number." & Chr(10) & Chr(10) _
& "Or press [Esc] key to cancel input.", vbExclamation, "Double entry!"
DoCmd.CancelEvent
DoCmd.RunCommand acCmdUndo
End If
But I have 2 problems:
1. If a duplicate value is entered an MS Access message pops up following my message box says "The value in the field or record violates the validation rule for the record or field." with an example and explanation. Even though I have no validation rule set for the field. I don't know why it comes out and how to get rid of it.
2. After clicking OK to close the message box, I can enter a new value. But if I want to cancel data entry I need to press Esc twice. The first time I press Esc the value I just entered re-appears, I have to press Esc again to cancel the input of a new record. How can I cancel input with only one Esc key press?
Thanks.
Peter