Set Focus

socko139

Registered User.
Local time
Today, 11:05
Joined
Feb 22, 2001
Messages
25
Ok ..Finally I see some light here. I finished my validate code, but one problem.... my code is not setting focus properly upon error. Although it works when I apply my code to a command button (Ive created an Excel form with multiple text boxes) it will not work when I tab out of the field. I mean I receive the correct error message, but it just tabs out of the field and does not set the focus back into the errored text field. My code is as follows:

Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox4.Text) Then
MsgBox "Please input a valid time."
TextBox4.SetFocus
Else
TextBox4 = Format(TextBox4.Text, "hh:mm:ss AMPM")
End If

End Sub

Any help setting the focus back to the error field?? It has to be something with that textBox4.set focus line of code... Im not including. . .Thanks -C
 
Move the code to the BeforeUpdate event of the control. Then remove the SetFocus and replace it with -
Cancel = True

Please don't post the same question multiple times. If you have trouble with an answer, use the same thread to post follow on questions.

[This message has been edited by Pat Hartman (edited 11-05-2001).]
 

Users who are viewing this thread

Back
Top Bottom