Click event has priority over exit event

pbuethe

Returning User
Local time
Today, 14:56
Joined
Apr 9, 2002
Messages
210
I have a form some of whose controls have OnExit events. These events are to go to a different control next depending on the value entered. When the form is opened, the first of these controls has the focus. When I click a button on the form to go to another form, I have to click it several times while the focus goes through some of these controls. How do I get it to ignore the OnExit events when the button is clicked? Thanks for your help.
 
Set a Form Level Boolean Variable, set it equal to False on the Open Event of the Form.

When Ever a button is pressed that you want the OnExit Event to ignore set this variable equal to True.

Move all of your OnExit Code to the

Private Sub Form_Unload(Cancel As Integer)
Cancel=fDoExit

If Cancel=False then
'Continue closing
...
Else
'Don't Close
End If

End Sub

Set the Cancel equal the Forms Boolean Variable
 
Thanks for your response, Travis, but I need some clarification.

Where is the variable set to True? in the OnClick code?
Is that before or after the Docmd.Close?

Then does the OnExit code go in the Else part (=True) in the Unload event?
What goes in the first part (If Cancel = False)? nothing?

Much thanks...
 
Where is the variable set to True? in the OnClick code?
Is that before or after the Docmd.Close? Before

Then does the OnExit code go in the Else part (=True) in the Unload event?Nothing Since Setting Cancel=True will cancel the close event


What goes in the first part (If Cancel = False)? nothing?Any code that you want to run prior to the Close Event Closing the form successully


Don't forget to set the variable back to False as the last thing in the Click_Event of the button.
 
Thanks Pat, it worked when I changed the code to the AfterUpdate events. That was easy! :)
 

Users who are viewing this thread

Back
Top Bottom