Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q: How do I force a macro to run when user closes Access database ...

Status
Not open for further replies.

Cosmark

Technical User
Apr 18, 2001
9
CY
Q: How do I force a macro to run when user closes Access database from the close button (the X at the top right) of the Access window.

My application "relies" on the user to exit the database from a button on my main window. The macro attached to this button restores some Accees settings as well as deletes some temporary tables which are used by the system to process data. These temporary tables are very large, up to 50% of the size of the database.

If the users justs closes the Access window this macro does not run. Is there a way to identify this action by the user so that I can get this macro or any other VBA procedure to run when this happens ? or disable the X button on the Access window ?

Thanks in advance.

Cosmark
 
go to this website

Look at Tip # 19, it will provide you with code to Disable the Close Button on the Application Window.

Or you could create a form that you open as hidden when your application opens. Then in the Close Event of this hidden form, you could provide the code to perform the necessary clean up actions. In order to prevent the code from happening twice (once when you click on the proper Close button, and again when this hidden form closes, you can create a Public Variable that you can check the value of prior to performing the actions. You can set this variable to True when the Close Button on your form is clicked, then in your hidden form add an "If - Else - End If" statement to check this variable, and if it's True you don't perform the actions, otherwise you do.

PaulF
 
Thanks PaulF for your response.

I have checked Calvin's web site and found EXACTLY what I am looking for and more...

Thanks again, all the best.

Cosmark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top