Change focus to control

J

John Barnes

Have a subform which contains two dates. Have code
written to check for WorkEndDate >= WorkStartDate. Code
is assigned to OnLostFocus. If ... Then statement
executes code properly and displays a message box alerting
user that the work end date must be greater than or equal
to work start date.

My problem is that I can't figure out how to return focus
to the WorkEndDate on the subform to force the user to
change their entry. Have tried macro with GoToControl, as
well as WorkEndDate.SetFocus. Neither work, the focus
moves to the next control in the tab order.

If I put a macro button on the subform and run GoToControl
from macro, then focus sets properly.

I need to find out how to set focus back to WorkEndDate
from within code (as part of if then statement.)

Thanks!
 
K

Ken Snell [MVP]

Use the Exit event, not the LostFocus event. The Exit event allows you to
modify the focus as part of the event, the LostFocus event is too late to
change where the focus is going.
 

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