Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Validation of Data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim - 29 Sep 2006 16:57 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.