Hi I have this code below that is supposed to check if the SONum that was input starts with a 0 but I get a type mismatch and I am not sure why.
Code:
Dim ZeroCheck As String: ZeroCheck = Left(SONum, 1) = "0"
Select Case Len(SONum)
Case 6
If ZeroCheck Then
SO_Err = True 'MsgBox ("Invalid Sales Order." & vbCrLf & "Please check that you didn't miss a number")
GoTo ERR_InvalidSONum
ElseIf Not ZeroCheck Then
SONum = Format(SONum, "0000000")
GoTo FormatCorrect
Else
MsgBox "How did you get here? Contact and admin and tell them"
SO_Err = True
GoTo ERR_InvalidSONum
End If
Case 7
If ZeroCheck Then
GoTo FormatCorrect
ElseIf Not ZeroCheck Then
SO_Err = True 'MsgBox ("Invalid Sales Order." & vbCrLf & "Please check if you accidentally double typed a number")
GoTo ERR_InvalidSONum
Else
SO_Err = True 'MsgBox "How did you get here? Contact and admin and tell them"
GoTo ERR_InvalidSONum
End If
Case Else
SO_Err = True 'MsgBox ("Invalid Sales Order." & vbCrLf & "Too many numbers in the first part")
GoTo ERR_InvalidSONum
End Select
I even tried changing the ZeroCheck around and I get the below results
Code:
ZeroCheck = "Left(SONum, 1) = ""0""" '(Line 4 mismatch)
ZeroCheck = Left(SONum, 1) = "0" '(Line 7 mismatch)
If I change line 7 to this it works which is fine. I just want to understand what I am doing wrong so I can learn for the future.
Code:
ElseIf ZeroCheck = False Then
Thanks for helping me understand!