Focus Problem

K

Kevin

I have a form with a date field. In the Afterupdate event
for the field, I check to ensure the date is not a future
dat. If it is, the user gets a message indicating that a
future date can not be entered. After acknowleding the
message, the field is clear and the focus is supposed to
return to the date field.

My code is similar to the following:

If(me!mydatefield>now()) then
MsgBox "You may not enter a future date!"
Me!mydatefield= ""
Me!mydatefield.SetFocus
End If

When this runs, the message is issued, the field value is
cleared and focus moves to the next field in the tab
order. Why?

Any help would be appreciated!

Kevin
 
R

Rick Brandt

Kevin said:
I have a form with a date field. In the Afterupdate event
for the field, I check to ensure the date is not a future
dat. If it is, the user gets a message indicating that a
future date can not be entered. After acknowleding the
message, the field is clear and the focus is supposed to
return to the date field.

My code is similar to the following:

If(me!mydatefield>now()) then
MsgBox "You may not enter a future date!"
Me!mydatefield= ""
Me!mydatefield.SetFocus
End If

When this runs, the message is issued, the field value is
cleared and focus moves to the next field in the tab
order. Why?

Validation should be done in BeforeUpdate, not AfterUpdate. The reason is
that if the validation test fails you can set the Cancel argument to True.
This means the update event never happens and focus doesn't change.

However; I typically reserve BeforeUpdate validation for fairly complex
validation criteria. You could simply use a ValidationRule property and
get the results you want with no code at all. Just enter <Now() in the
ValidationRule and your error text in the ValidationText property.
 

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