Looking for help with DLookup function VBA using If Else conditions. I have a form for adding new carriers to an existing carrier table. Because I know these users :banghead:, I would like for it to:
1. If the ID No. field is left blank - show an error message in an unbound text box.
2. If the ID entered in the ID No. Field already exists in the table - display an error message in an unbound text box and display the the carrier ID and Name associated with it.
I have it set on the got focus of the field immediately after the ID No. Field. I've searched and search and tried a number of ways, i know it's probably a syntax issue. Any help is much appreciated.
Here is what I have so far:
If IsNull(Me.AddCarrierNo) Then
Me.ErrMesgBoxTxt = "Please enter a Carrier/SI No."
Else
If DLookup("[CarrierNo]", "ExamCarrier", "[CarrierNo] = " & Me.AddCarrierNo) = True Then
Me.ErrMesgBoxTxt = "Carrier/SI Number already exists. Please verify Carrier information."
Me.ErrMesgBoxTxt.Requery
Me.ErrMesgBoxID = DLookup("[CarrierNo]", "[ExamCarrier]", "[CarrierNo] = " & Me.AddCarrierNo)
Me.ErrMesgBoxID.Requery
Me.ErrMsgBoxName = DLookup("[CarrierName]", "[ExamCarrier]", "[CarrierNo] = " & Me.AddCarrierNo)
Me.ErrMsgBoxName.Requery
End If
End If
1. If the ID No. field is left blank - show an error message in an unbound text box.
2. If the ID entered in the ID No. Field already exists in the table - display an error message in an unbound text box and display the the carrier ID and Name associated with it.
I have it set on the got focus of the field immediately after the ID No. Field. I've searched and search and tried a number of ways, i know it's probably a syntax issue. Any help is much appreciated.
Here is what I have so far:
If IsNull(Me.AddCarrierNo) Then
Me.ErrMesgBoxTxt = "Please enter a Carrier/SI No."
Else
If DLookup("[CarrierNo]", "ExamCarrier", "[CarrierNo] = " & Me.AddCarrierNo) = True Then
Me.ErrMesgBoxTxt = "Carrier/SI Number already exists. Please verify Carrier information."
Me.ErrMesgBoxTxt.Requery
Me.ErrMesgBoxID = DLookup("[CarrierNo]", "[ExamCarrier]", "[CarrierNo] = " & Me.AddCarrierNo)
Me.ErrMesgBoxID.Requery
Me.ErrMsgBoxName = DLookup("[CarrierName]", "[ExamCarrier]", "[CarrierNo] = " & Me.AddCarrierNo)
Me.ErrMsgBoxName.Requery
End If
End If