Text Verification -- can't make it work

C

corky_guy

Trying to limit the entry of text to a string like this:
1234:BUNCH_OF_NUMBERS

The critical part is: 1234: cannot be changed (i.e., will always be
four numbers with a colon)
Everything after the colon can only be numbers but no limitation in
length (and numbers only)

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox2
If Not .Text Is "[1][2][3][4][:]" And [0 - 9] Then
MsgBox "Please do something"
Cancel = True
End If
End With
End Sub

But, it's not working! I've tried a million different combinations of
strings w/ and w/out quotes, brackets, etc!

Anyone?
 
R

Russ

Try:
If Not .Text Like "####:#" Then
Trying to limit the entry of text to a string like this:
1234:BUNCH_OF_NUMBERS

The critical part is: 1234: cannot be changed (i.e., will always be
four numbers with a colon)
Everything after the colon can only be numbers but no limitation in
length (and numbers only)

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox2
If Not .Text Is "[1][2][3][4][:]" And [0 - 9] Then
MsgBox "Please do something"
Cancel = True
End If
End With
End Sub

But, it's not working! I've tried a million different combinations of
strings w/ and w/out quotes, brackets, etc!

Anyone?
 
R

Russ

I just noticed that you require more, so try:

If Not Left(.Text,5) Like "####:" Or _
Not IsNumeric(Mid(.Text,6)) Then

Try:
If Not .Text Like "####:#" Then
Trying to limit the entry of text to a string like this:
1234:BUNCH_OF_NUMBERS

The critical part is: 1234: cannot be changed (i.e., will always be
four numbers with a colon)
Everything after the colon can only be numbers but no limitation in
length (and numbers only)

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox2
If Not .Text Is "[1][2][3][4][:]" And [0 - 9] Then
MsgBox "Please do something"
Cancel = True
End If
End With
End Sub

But, it's not working! I've tried a million different combinations of
strings w/ and w/out quotes, brackets, etc!

Anyone?
 

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

Similar Threads


Top