Data entry mask or data checking on a Userform Textbox (agai

AJ

Active Member
Joined
Mar 4, 2002
Messages
478
Hi Everyone,

Before I start I think we've been here before but the posts I've found through searching, while useful, haven’t exactly helped me.

I have a textbox on a userform whereby I only want to allow the user to enter 6 characters, of which the first three must be alpha characters and the last three must be numerics.

There are two approaches therefore as far as I can see.

1. Let them enter whatever they please and check the format after
2. Restrict entry into the actual textbox.

In the first case I can see one way of doing it which is basically an enormous series of checks (i.e. IF statements I guess) and throw error messages back at the user and re-present the form. I can see myself creating enormous amounts of code though so I wondered if the board members might be able to do this in a far tidier fashion than I can??

In the second case, I don’t know how to do this at all.
In the following two threads, TSTom talks about Microsoft Masked Edit.

http://www.mrexcel.com/board/viewtopic.php?topic=4674&forum=2
http://www.mrexcel.com/board/viewtopic.php?topic=10170&forum=2

I do have this feature available when I right click my VBA toolbox, however, I get the same error reported as Mr Nick in the first of the two threads. Any ideas on how I get this little feature to work?

Thanks a lot folks.

Rgds
AJ
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Actually your example is not difficult to implement with a standard Textbox:

Code:
Private Sub TextBox1_Change()
    Dim Char As String
    Char = UCase(Right(TextBox1.Text, 1))
    Select Case Len(TextBox1.Text)
    Case 1 To 3
        If Char Like "[A-Z]" Then Exit Sub
    Case 4 To 6
        If Char Like "#" Then Exit Sub
    End Select
    Beep
    On Error Resume Next
    TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
    TextBox1.SelStart = Len(TextBox1.Text)
End Sub
This message was edited by Andrew Poulsom on 2002-11-27 12:06
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,108
Members
449,205
Latest member
ralemanygarcia

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