Using code on the net I put together this:
Private Sub tbxDrug_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.tbxDrug
If Not Like "[A-Z][A-Z]###" Then
MsgBox "blah blah"
Cancel = True
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End If
End With
End Sub
This is supposed to validate that the entered data is in the format a
AA123.
But it seems IF NOT LIKE is not a valid command. Is it valid or do I
need to go about this another way?
Jim
Dave Lett - 29 Sep 2006 18:16 GMT
Hi Jim,
You can set up the logical structure of the If statement to account for IF
Not
Dim sString As String
sString = "AJ123"
If sString Like "[A-Z][A-Z]###" Then
''' do something
Debug.Print True
Else
'''your routine
Debug.Print False
End If
HTH,
Dave
> Using code on the net I put together this:
>
[quoted text clipped - 17 lines]
>
> Jim
Tony Jollans - 01 Oct 2006 15:41 GMT
There is nothing really wrong with not like. What is wrong is that you can't
have an implicit comparand. The syntax is ...
If Not .Text Like "[A-Z][A-Z]###" Then
--
Enjoy,
Tony
> Using code on the net I put together this:
>
[quoted text clipped - 17 lines]
>
> Jim