Conditional statments in VBA

Dylan Snyder

Registered User.
Local time
Today, 07:13
Joined
Dec 31, 2007
Messages
89
does somebody know of a good tutorial on conditional statments in VBA? Some times I write them and they work. Other times, they just run as though the condition is always true, no matter if it is or not. Does anyone know of a good tutorial or can provide me with a "lighbulb" reason for why the below code does not work? Thanks

If Me.UPC_Number Like "************" Then
Me.UPC_Type = "UPC"
ElseIf Me.UPC_Number Like "*************" Then
Me.UPC_Type = "EAN"
Else
MsgBox "UPC Number must contain either 12 or 13 digits."
End If
 
The asterisk is a wildcard, so the first condition will always be true. It looks like you're testing for length, so try

If Len(Me.UPC_Number) = 12 Then
 
oh, of course. That was a rookie mistake. Thanks.
 

Users who are viewing this thread

Back
Top Bottom