Maneesh Massey
Member
Hello Everyone,
I have been raking my brains out on this one for the past one week but haven't found anything useful the this topic. Maybe I was not looking in the right place.
I have been working with Text box validation techniques for the past week and need to validate user input from the userform in an Excel VBA application. I need to check to see for example, that no one enters numeric values into a text box which built for string entries. (You will admit, it is next to impossible to validate every entry the user can make into a form.) Like for example, how can you validate an email address ??
The question that I want to address is : why does the Text box's .SetFocus method not work and put the cursor into the textbox with the following code:
By the way, Arec7 is the name of the textbox given above.
I tried the Cancel=True method too but this gives odd behavior to the functionality of the form and the cursor becomes "Sticky", meaning to say, the cursor becomes stuck in the textbox and is unable come out. No other button works except the 'X' close button on the userform.
So, why does the .SetFocus method not work ??? And what is the best way to validate string values, numeric values and email addresses ??? I want to validate each textbox entry on KeyPress method while the user is still typing instead of before leaving the userform. It makes no sense to me to validate textbox entries when the user is out of the textbox and about to leave the form.
Would anyone like to help please ?? Greatly appreciate all help !
Regards,
~~ Maneesh
I have been raking my brains out on this one for the past one week but haven't found anything useful the this topic. Maybe I was not looking in the right place.
I have been working with Text box validation techniques for the past week and need to validate user input from the userform in an Excel VBA application. I need to check to see for example, that no one enters numeric values into a text box which built for string entries. (You will admit, it is next to impossible to validate every entry the user can make into a form.) Like for example, how can you validate an email address ??
The question that I want to address is : why does the Text box's .SetFocus method not work and put the cursor into the textbox with the following code:
Code:
Private Sub Arec7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(Me.Arec7.Value) Then
MsgBox "Please enter a valid name."
Arec7.SetFocus
ElseIf Me.Arec7.Value = "" Then
MsgBox "You must enter a name."
Arec7.SetFocus
End If
End Sub
I tried the Cancel=True method too but this gives odd behavior to the functionality of the form and the cursor becomes "Sticky", meaning to say, the cursor becomes stuck in the textbox and is unable come out. No other button works except the 'X' close button on the userform.
So, why does the .SetFocus method not work ??? And what is the best way to validate string values, numeric values and email addresses ??? I want to validate each textbox entry on KeyPress method while the user is still typing instead of before leaving the userform. It makes no sense to me to validate textbox entries when the user is out of the textbox and about to leave the form.
Would anyone like to help please ?? Greatly appreciate all help !
Regards,
~~ Maneesh