View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
K[_3_] K[_3_] is offline
external usenet poster
 
Posts: 9
Default How to get User input from Userform Text box

Thank you for the response. I (newbie) am confused about the flow. Is it

cmbGo_Click ( )
txtStopDate.SetFocus
txtStopDate.Start = 0
txtStopDate.SelLength =8
Call ValidateDate
End

ValidateDate ( )
'Test for validity of date

If DateFound = 0 Then Inform user and Exit
....
End

The User enters a date and clicks the Go button.
The Click checks the length of the text entry (=8) and calls the procedure to
validate the date?
The ValidateDate procedure finds an error (informs the user) and exits?

Thanks


Ronald Dodge wrote:

The side affect that you are seeing is probably a result of the code
constantly running with the Do...Until code, thus not refreshing the screen
as you would like it to. To avoid this sort of issue, 2 things to consider:

Setup a command button and use as the default button for when the date is
entered (if not already done),

and

If the data validation did not pass on the date entry, use the SetFocus
within the command button's click event on the Date's textbox object, then
set the SelStart and SelLength properties on the textbox.

--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"K" wrote in message
...
In this situation the User inputs an invalid date in a Userform text
box, the program then requests a valid date.

I used the Do Until command to pause the program
while the User inputs the new date. However, the UserForm disappears (or
partially visible and
stuck) so its not possible to make the change. I tried UserForm1.Show
as shown in the coding
below, but this yields an error (the Userform is already showing).
Appreciate any suggestions.

If DateFound = 0 Then 'The date provided is not valid
LabelMessage.Caption = "Database does not contain specified Stop Date.
Please enter new Stop Date"

txtStopDate.Value = "" 'Clear the text box containing the
wrong date
txtStopDate.SelStart = 0
txtStopDate.SelLength = Len(txtStopDate.Text)
txtStopDate.SetFocus

Do Until Len(txtStopDate) = 8 'Check that the text box
contains a date
UserForm1.Show 'This code creates an error
Loop
GoTo StopDate 'This validates the newly provided

End If