Validation of Data

J

Jim

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
 
D

Dave Lett

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
 
T

Tony Jollans

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top