Moving cursor

A

Ann

I'm just starting to learn VBA and am having problems moving the cursor. I
have the following code:

Private Sub txtInterviewDate_AfterUpdate()

If txtInterviewDate.Value < txtGBStartDate Then
MsgBox "The InterviewDate must be greater then or equal to the
GBStartDate"
txtInterviewDate.Value = Null

End If

End Sub

This does work fine but the cursor moves to the next textbox and I want it
to be in txtInterviewDate textbox so the date can be re-entered. It's
probably really simple but the different things I tried don't work. Thanks
for the help.
 
J

Jay Freedman

Ann said:
I'm just starting to learn VBA and am having problems moving the
cursor. I have the following code:

Private Sub txtInterviewDate_AfterUpdate()

If txtInterviewDate.Value < txtGBStartDate Then
MsgBox "The InterviewDate must be greater then or equal to the
GBStartDate"
txtInterviewDate.Value = Null

End If

End Sub

This does work fine but the cursor moves to the next textbox and I
want it to be in txtInterviewDate textbox so the date can be
re-entered. It's probably really simple but the different things I
tried don't work. Thanks for the help.

A better idea is to use the Exit event handler, which has a Cancel argument.
If you don't want the cursor to move out of the text box that got the event,
you set the Cancel value to True. Like so:

Private Sub txtInterviewDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If txtInterviewDate.Value < txtGBStartDate Then
MsgBox "The InterviewDate must be greater than or equal to the
GBStartDate"
txtInterviewDate.Value = Null
Cancel = True
End If

End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
A

Ann

Thank you so much! That did exactly what I wanted. Can you possibly tell me
of any books or websites that will explain all the event handlers?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top