Put a MsgBox in the code at the beginning and see if it displays.
I put in this:
Private Sub Form_Load()
MsgBox “Haha!”, , "Laugh"
End Sub
And upon opening the form, I got the following message:
Run-time error '424':
Object required
Change it to: MsgBox "Haha!" and put it in the Batch_Number code.
I put in:
Private Sub Batch_Number_GotFocus()
MsgBox "Haha!"
End Sub
That worked perfectly!
Thanks so much for all your trouble. Now we just need to get the conditional message box right...
I truly appreciate your help!
You need to put that MsgBox in the BeforeUpdate event of the Batch_Number control so we can make sure it is executing.
That worked perfectly!
Are you now rejecting duplicate numbers?
No, the message box with the "Haha" only worked. I tried the code you suggested again, but no luck.
Please post *all* of the code you currently have in the BeforeUpdate event that includes the MsgBox.
This is all.
If I include
MsgBox "Haha!"
Then this message box appears as one moves to the next field, but the message (=[MacroError].[Description]) appears only when saving the whole form at the end of completing all the fields.
Here's the code:
Private Sub Batch_Number_BeforeUpdate(Cancel As Integer)
With Me.RecordsetClone
.FindFirst "LotNumber ='" & Me.Batch_Number & "'"
If Not .NoMatch Then
MsgBox "This batch number [" & Me.Batch_Number & "] has already been logged!" & vbCrLf & _
"For Re-Assays, add suffix RE1 or RE2, as necessary.", vbOKOnly, "Duplicated entry"
Me.Batch_Number.Undo
Cancel = True
End If
End With
End Sub
If I leave out
[" & Me.Batch_Number & "]
in
MsgBox "This batch number [" & Me.Batch_Number & "] has already been logged!" & vbCrLf & _
it still does the same.
Something is not right. Any chance you can post your db? Zip it up first.
This is mind boggling. It worked once, then not again. I changed nothing.
I zipped the DB. Hope this works.
What is the password?
You cam PM me if you don't want it to be public.