?
Solved

Run code when Access Closes

Posted on 2009-04-01
3
Medium Priority
?
518 Views
Last Modified: 2013-11-27
I would like to run a line of code when my Access program closes.  I would like it to run if the user clicks the "X" at the top right or if they click the exit button on the form I have.  Basically, when the entire application closes I would like to run some code, but I have no idea where the event would go.

Thanks
0
Comment
Question by:adbusbee
3 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 600 total points
ID: 24040632
 The way to do this is to open a hidden form at startup.  When Access closes, this will be the first form to close.  You can place anything you need in the OnClose event of that form.
JimD.
0
 
LVL 14

Assisted Solution

by:pteranodon72
pteranodon72 earned 400 total points
ID: 24040719
You want to create a non-visible startup form (Form design -> Format -> visisble = false) and put the code in the close event of that form.  Set it in Database->Startup. If you already have a startup form specified there, just add

DoCmd.OpenForm "yourRegularStartUp" in the Open Event of the new, non-visible form.

When access quits, it unloads forms in the opposite order they were openned.

The only situation this does not protect against is Ctrl-Alt-Delete -> End Program on Access.

HTH,

pT
0
 

Author Comment

by:adbusbee
ID: 24040791
Worked perfectly.  Good idea, thanks!
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question