Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data validation in Userform sub
If a user enters the wrong info into a textbox control, how do I program the
userform to display an error message and return the user to the textbox to enter the correct info? I've tried using the Exit event with a MsgBox inside a Do While...Loop, but either the MsgBox keeps looping, or the focus switches to the next control, even if I use the SetFocus method: Private Sub ControlNumb_Exit(ByVal Cancel As MSForms.ReturnBoolean) Do While IsNumeric(NewResEntryForm.ControlNumb.Value) = False _ Or Len(NewResEntryForm.ControlNumb.Value) < 5 response = MsgBox("Please enter a valid control number", vbOKOnly) If response = vbOK Then NewResEntryForm.ControlNumb.SetFocus Exit Sub End If Loop End Sub Please help, thanks. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data validation in Userform sub
Try the below.
Private Sub ControlNumb_Exit(ByVal Cancel As MSForms.ReturnBoolean) If IsNumeric(Me.ControlNumb) = False Or Len(Me.ControlNumb) < 5 Then MsgBox "Please enter a valid control number", vbOKOnly Cancel = True End If End Sub If this post helps click Yes --------------- Jacob Skaria "Marcolino" wrote: If a user enters the wrong info into a textbox control, how do I program the userform to display an error message and return the user to the textbox to enter the correct info? I've tried using the Exit event with a MsgBox inside a Do While...Loop, but either the MsgBox keeps looping, or the focus switches to the next control, even if I use the SetFocus method: Private Sub ControlNumb_Exit(ByVal Cancel As MSForms.ReturnBoolean) Do While IsNumeric(NewResEntryForm.ControlNumb.Value) = False _ Or Len(NewResEntryForm.ControlNumb.Value) < 5 response = MsgBox("Please enter a valid control number", vbOKOnly) If response = vbOK Then NewResEntryForm.ControlNumb.SetFocus Exit Sub End If Loop End Sub Please help, thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Dynamic userform help - Data Validation | Excel Programming | |||
Userform - validation data. Please help needed | Excel Programming | |||
Data validation using TextBox in UserForm | Excel Programming | |||
Data validation within a userform | Excel Programming | |||
Using a Userform instead of Data Validation | Excel Programming |