Forcing specific text into form

craigo

New Member
Joined
Aug 29, 2006
Messages
17
Hello, I again come with a quick-fix problem (I think).

I have a field (VisitorID) filled by users via a form. I want to ensure that the format is followed so data can later be searched.
The format is AB-1234. That is, 2 letters, a dash, and 4 numbers.
I want to make sure the first 2 are alphas, the last 4 are digits and the dash is always used.
I found out how to make sure there are 7 characters, and trim spaces, but that isn't enough to eliminate user error.
Here is a basic sample of the code I'm trying to do:

Private Sub Okay_Click()

'something must go here to validate the input

Range("g8").Value = TextBox1.Value


End Sub
I would appreciate any help that can be provided!
Thank you
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi,
untested but try

Code:
Private Sub Okay_Click()
    With Me.TextBox1
        If .Text Like "[A-Z][A-Z]####" Then
            Range("g8").Value = .Value
        Else
            MsgBox "Invalid Entry", 48, "Invalid"
            .SetFocus
        End If
    End With
End Sub



Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top