Code:
Dim FoundNotFound As Variant, Response As Variant
FoundNotFound = DLookup("LotNumber", "BatchT", "LotNumber='" & Me.LotNumber & "'")
If Not IsNull(FoundNotFound) Then
Response = MsgBox("Lot number already in use. Check Batch List for next available number", vbOKOnly)
If Response = vbOK Then
Cancel = False [COLOR=Red](Originally Cancel = True")[/COLOR]
End If
End If
(This code isn't mine, I found it online, and it was probably here)
I put this code in the Before Update event on the user form for the LotNumber text box. As you can see from my note above, the original value for Cancel was True. In the case of LotNumber data there are rare occasions when its acceptable to reuse a Lot Number, so I wanted to prompt the user, but allow a duplicate as well, so No Duplicates is turned off at the table level. What was happening was that the message box would just come back up each time I moved to the next data entry item. I don't understand Access VBA very well, but by experimenting I found that by changing it to Cancel = False it performs as intended. Can anyone help me understand why?