Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 26 Aug 2008 10:33:18 -0700 (PDT),    group: microsoft.public.word.vba.beginners        back       


How to use an 'Or Operator'   
Hi -
I'm trying to write a simple bit of code that simply checks for proper
formatting of text.  The problem is that the code I have used does not
seem to properly work.  Can someone offer a suggestion of how to fix?

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
    If (Not Left(.Text, 3) Like "so-") Or (Not Left(.Text, 3) Like
"t3-") Then
    MsgBox "so-x/x/x or t3-x/x/x"
    Cancel = True
    End If
End With
End Sub


Basically, the inputted text MUST BE either: so-x/x/x or t3-x/x/x --
it cannot be anything other than that.

Thank you for any help you can provide.
date: Tue, 26 Aug 2008 10:33:18 -0700 (PDT)   author:   unknown

Re: How to use an 'Or Operator'   
corky_guy

Look at your logic:

My house is white

If my house isn't white OR my house isn't black Then
   Msgbox "Since your house isn't black you see this message"
End If

Now consider:

My house is white

If my house isn't white AND my house isn't black Then
   Msgbox "Since your house is white And it isn't black you don't see this 
message"
Else
  Msgbox "Since your house is black or white you see this message"
End If

and this:


My house is blue

If my house isn't white AND my house isn't black Then
   Msgbox "Since your house isn't white And it isn't black your must be some 
other color"
Else
  Msgbox "Since your house is black or white you see this message"
End If

Try:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
  MsgBox Left(.Text, 3)
  If Not Left(.Text, 3) Like "so-" And Not Left(.Text, 3) Like "t3-" Then
  MsgBox "so-x/x/x or t3-x/x/x"
  Cancel = True
  End If
End With
End Sub


corky_guy@yahoo.com wrote:
> Hi -
> I'm trying to write a simple bit of code that simply checks for proper
> formatting of text.  The problem is that the code I have used does not
> seem to properly work.  Can someone offer a suggestion of how to fix?
>
> Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> With Me.TextBox1
>    If (Not Left(.Text, 3) Like "so-") Or (Not Left(.Text, 3) Like
> "t3-") Then
>    MsgBox "so-x/x/x or t3-x/x/x"
>    Cancel = True
>    End If
> End With
> End Sub
>
>
> Basically, the inputted text MUST BE either: so-x/x/x or t3-x/x/x --
> it cannot be anything other than that.
>
> Thank you for any help you can provide.

-- 
Greg Maxey -  Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
date: Tue, 26 Aug 2008 14:21:57 -0400   author:   Greg Maxey RrOMEOgOLF

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us