Form 'On Close' event not firing

mascott

New member
Local time
Today, 15:55
Joined
Sep 16, 2009
Messages
4
I have created a hidden form that opens with an autoexec macro when I open my database. It does some startup routines that run fine. However, I also need to do some clean up on shutdown so I have hooked some code on the 'On Close' event of the hidden form. When I exit Access 2007 SP2 from the application X, or call doCmd.quit, the form 'On Close' never fires. I have tried creating a new stripped down database with only a autoexec and the startup form, still with no luck. I even went so far as to leave the form visible when it opens. When I manually close the form, it fires. If I close Access, it does not fire. Can anyone help here? I feel like this should be simple?
 
how have you verified that the event is not firing? And what is the code in the On Close event?
 
For testing purposes I simply put a stop command in the On Close event. I also tried a messagebox. Neither worked when I X'd out of Access. They did work fine however when I closed the form manually.
 
Well, depending on what you have for code in there, you might be able to use the form's UNLOAD event which should fire regardless. I use that frequently to stop someoine from using the X on the application.
 
Thank you very much! The Unload event does fire when I exit. That will fix my problem. Leaves me to wonder though why the Close event isn't set up to fire on exit? Microsoft, any comments?
 
I ran up a db using your scenario, and in v2003, the Form Close event does, indeed, execute when closing Access using the Big X, even when the form is hidden. Usually when things don't work as they demonstratively should, you're talking about corruption. It does take on many strange and wondrous appearances!
 
I ran up a db using your scenario, and in v2003, the Form Close event does, indeed, execute when closing Access using the Big X, even when the form is hidden. Usually when things don't work as they demonstratively should, you're talking about corruption. It does take on many strange and wondrous appearances!

I had thought of that before myself. I created and brand new blank database, added a new blank form with events on the 'on open' and 'on close', added the autoexec to start it up when I open the database. I even went so far as to do the Allen Browne technique of decompiling and turning off the AutoCorrect and it still would not fire the 'On Close', but it does fire the 'On Unload'. Maybe Access 2007 with the accDb format changed how events are fired on application exit???
 
go to design view on the form then properties and make sure the "on close" event is set to [event procedure]. It made the difference to me.
 
DUH! :banghead:
I cannot believe I fell for the old "paste code and forget to setup event" trick. AGAIN
Added OnClose as Event and everything worked.
 

Users who are viewing this thread

Back
Top Bottom