Textbox number validation
Posted by Bob on June 08, 2001 11:09 AM
I asked this question a while back and got a long keypress function validation macro that I don't want to get into. I have 3 separate textboxes in a userform I am using for a social security number input, and want to make sure the user inputs 3 numbers in the first, 2 in the second, and 4 in the third. Most importantly, I want to make sure they're numbers. I've looked all over the internet and found certain code that sets the focus on the textbox, but I can't get that to work. No matter what I have done (using others' code), after pressing ok on the message box, it tabs to the next textbox. Here's what I have currently for the first textbox:
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox3.Value) Then
MsgBox "INVALID ENTRY"
.SelStart = 0
.SelLength = 1000
This works for the error, but goes on to wherever I clicked the mouse on after pressing ok. I have also tried the cancel = true and tryagain = true type routines I've found, but still can not get the cursor back into textbox3. Any help is greatly appreciated.