Compile Error Else Without If

bconner

Registered User.
Local time
Today, 16:55
Joined
Dec 22, 2008
Messages
183
I have a text box with a DLookup that will return "Not Found" or a Number > 0 when it loses focus. Below is the code I am using
I keep getting the compile error Else without If, any help is greatly appreciated.....

Code:
Private Sub txtCodingBatch_LostFocus()
Dim vTempCodingEntryBatchVerify As String
vTempCodingEntryBatchVerify = Nz(DLookup("CountOfAccession", "QryCodingEntryBatchVerify"), "Not Found")
Me![txtCodingEntryVerifyBatch] = vTempCodingEntryBatchVerify
If Me![txtCodingEntryVerifyBatch] = "Not Found" Then MsgBox "Invalid Batch, Please ReEnter Valid Batch Number"
Me![txtCodingBatch].SetFocus
ElseIf Me![txtCodingEntryVerifyBatch] <> "Not Found" Then Me![txtDateSignedOutToCoding].SetFocus
 
End If
End Sub
 
This is how your If statement should be written...

Code:
If Me.[txtCodingEntryVerifyBatch] = "Not Found" Then
     MsgBox "Invalid Batch, Please ReEnter Valid Batch Number"
     Me.[txtCodingBatch].SetFocus
Else
     Me.[txtCodingEntryVerifyBatch] <> "Not Found"
     Me.[txtDateSignedOutToCoding].SetFocus
End If
 
Thanks, I used your code and took out the Me.[txtCodingEntryVerifyBatch] <> "Not Found" after Else and it worked! Thanks Again....

If Me.[txtCodingEntryVerifyBatch] = "Not Found" Then
MsgBox "Invalid Batch, Please ReEnter Valid Batch Number"
Me.[txtCodingBatch].SetFocus
Else

Me.[txtDateSignedOutToCoding].SetFocus
End If
 
Sorry about that, I did not notice what was in the Else for that would not work as is, as you discovered. ;-)
 

Users who are viewing this thread

Back
Top Bottom