I'm a novice and am having trouble getting a message box to work. I would like a message box to appear when someone is entering or updating a number in a control in a subform when there is a duplicate. The message box can then allow the person to continue (keep the duplicate if it's intentional) or delete the entire record (if it wasn't intentional).
I have the following coding for AfterInsert and AfterUpdate for the control in the subform:
If DCount("*", " Database-Number ", "[Number]="& Chr(34) & [Number] & Chr(34)) > 1 ThenCall MsgBoxDuplicateEnd If
I have entered the following for the message box in the subform, but nothing happens:
Sub MsgBoxDuplicate()
I tried starting with the basic coding and then adding one section at a time to figure out where the problem is. The message box appears for duplicates if I do this:Dim answer As Integer
answer = MsgBox("This number has already been entered. Would you like to continue? If this is an intentional duplicate, press Yes continue entering information. Otherwise press No to delete this entry.", vbYesNo + vbExclamation, "Duplicate Entry")
If answer = vbNo Then
answer = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbCritical, "Delete")
If answer = vbYes Then
DoCmd.RunCommandacCmdDeleteRecord
End If
End If
Sub MsgBoxDuplicate()
but as soon as I add "answer=(…)" it no longer appears. Any help would be much appreciated.MsgBox"This number has already been entered. Would you like to continue? If this is an intentional duplicate, press Yes continue entering information. Otherwise press No to delete this entry.", vbYesNo + vbExclamation, "Duplicate Entry"