Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-21-2004, 12:04 PM   #1
pbuethe
Returning User
 
pbuethe's Avatar
 
Join Date: Apr 2002
Location: Merrick, NY, USA
Posts: 192
Thanks: 3
Thanked 0 Times in 0 Posts
pbuethe
Click event has priority over exit event

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.

pbuethe is offline   Reply With Quote
Old 06-21-2004, 12:10 PM   #2
Travis
Registered User
 
Travis's Avatar
 
Join Date: Dec 1999
Location: Kingsburg, CA, USA
Posts: 1,332
Thanks: 0
Thanked 2 Times in 2 Posts
Travis is on a distinguished road
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
__________________
Travis L Abrahamson

Travis is offline   Reply With Quote
Old 06-21-2004, 12:31 PM   #3
pbuethe
Returning User
 
pbuethe's Avatar
 
Join Date: Apr 2002
Location: Merrick, NY, USA
Posts: 192
Thanks: 3
Thanked 0 Times in 0 Posts
pbuethe
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...

pbuethe is offline   Reply With Quote
Old 06-21-2004, 03:50 PM   #4
Travis
Registered User
 
Travis's Avatar
 
Join Date: Dec 1999
Location: Kingsburg, CA, USA
Posts: 1,332
Thanks: 0
Thanked 2 Times in 2 Posts
Travis is on a distinguished road
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.
__________________
Travis L Abrahamson

Travis is offline   Reply With Quote
Old 06-21-2004, 06:42 PM   #5
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 28,162
Thanks: 15
Thanked 1,574 Times in 1,496 Posts
Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all
Don't use the Exit event. Use the AfterUpdate event. That way your code won't be trying to move the cursor around unless someone actually changes something.
__________________
Bridge Players Still Know All the Tricks
Pat Hartman is online now   Reply With Quote
Old 06-22-2004, 04:52 AM   #6
pbuethe
Returning User
 
pbuethe's Avatar
 
Join Date: Apr 2002
Location: Merrick, NY, USA
Posts: 192
Thanks: 3
Thanked 0 Times in 0 Posts
pbuethe
Thanks Pat, it worked when I changed the code to the AfterUpdate events. That was easy!

pbuethe is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 07:45 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World