Link to home
Start Free TrialLog in
Avatar of Dennis_Gundersen
Dennis_Gundersen

asked on

Access: How to run code before file close (apposite of AutoExec)?

I'd like to do some clean-up of temporary tables whenever the user closes the Access file. Is there a way to do this, maybe like the AutoExec macro does for opening, but preferably in VBA?
TIA!
Dennis
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dennis_Gundersen
Dennis_Gundersen

ASKER

OK, thanks. It's a bit more involved than I would have guessed, but shouldn't be a problem.
Re
D
Note that you can cancel the close of Access by using Cancel = True in the OnUnload event if you find anything you don't like.  

Say the user has left forms or reports open other than a switchboard/menu form.

Use the OnClose event for clean-up once you've shut everything down you want in the OnUnload.

Jim.
By the way, that form is a nice place to store things as well, such as a user login name.  Or things like a company name and info.  

You can do that to avoid having to lookup data all the time.

It's also a great way to keep a persistent connection open to a backend, which if JET/ACE based, can give you a pretty big performance boost (depends on how your app works now).

Jim.
Side note ... this is a long standing request for an On Application Close event (et al).  It is now under consideration by the Access Product Team ... per access.uservoice.com