Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic userform help - Data Validation James Excel Programming 3 April 15th 09 02:48 PM
Userform - validation data. Please help needed Eduardo Excel Programming 2 December 12th 08 06:47 PM
Data validation using TextBox in UserForm Chris Excel Programming 3 January 26th 07 08:37 AM
Data validation within a userform kjenner7 Excel Programming 4 March 9th 06 03:37 PM
Using a Userform instead of Data Validation Knut Dahl Excel Programming 2 April 10th 05 11:02 AM


All times are GMT +1. The time now is 07:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"