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.
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