Do you mean, how to prevent the LostFocus event from firing? You can't.
Depending on what you're using the LostFocus event for, you may be able to
use some other event for the purpose, or else have some sort of flag that
you can check inside the LostFocus event to see whether you should skip the
rest of the event procedure. However, you won't be able to click elsewhere
to set that flag without triggering the event.
I agree with Dirk.LostFocusand OnExit are often used when the control's
BeforeUpdate or AfterUpdate event is more appropriate, or at times even
theForm_BeforeUpdate event.
to make sure a text box is filled as a validation rule.
the form also has a cancel button on it, the textbox with the
lostfocus validation fires when the cancel button is clicked.
not good....
to make sure a text box is filled as a validation rule.
the form also has a cancel button on it, the textbox with the
lostfocus validation fires when the cancel button is clicked.
not good....
You can't do it that way. Instead, I suggest you use the form's
BeforeUpdate event to check that this and any other required fields are
filled in. If they aren't, set the event procedure's Cancel argument to
True to abort the update, and display an appropriate message to the user.
In your Cancel button's Click event, undo the form before closing it; e.g.,
Private Sub cmdCancel_Click()
If Me.Dirty Then Me.Undo
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
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.