Code:
Dim CUSTID As String 'Customer Number
Dim CUSTNAME As String 'Customer Name
If Len(txtCustomerID.Value & "") = 0 Then Exit Sub
If Len(txtCustomerID.Value & "") > 0 And Len(txtCustomerID.Value & "") < 3 Then
MsgBox "You have entered an invalid number to be used as a Customer ID!" _
& Chr$(13) _
& "Please select no less than 3 numbers.", vbOKOnly, _
"Bad Number Entry")
GoTo CISFCF
End If
CUSTID = Nz(DLookup("CustomerID", "t_Customer", "CustomerID = '" & Forms!f_Customer!txtCustomerID & "'"))
CUSTNAME = Nz(DLookup("Customer_Name", "t_Customer", "CustomerID = '" & Forms!f_Customer!txtCustomerID & "'"))
If txtCustomerID.Value = CUSTID Then
MsgBox "You must create a different Customer ID number!" _
& Chr$(13) _
& CUSTNAME & "...Has already been assigned that number.", vbOKOnly, _
"Duplicate Customer ID") = vbOK Then
GoTo CISFCF
End If
CISFCF:
Me!btnCUSTSRCH.SetFocus
Me!txtCustomerID.SetFocus
Me!txtCustomerID.Value = ""
'Debug.Print CUSTID
'Debug.Print CUSTNAME
End Sub
You don't need the msgbox function to get the results you want. A display type messagebox will work. See the updated code. It gets rid of 2 IFs.
pbaldy (and you) are right. A better place for the code is in the before_update event.