How to Close Access Forms in Reverse Opening Order
Question details
The user wants to intercept the main application close event in Microsoft Access to close open forms in a last-opened-first-closed (reverse) order.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Managing form navigation and custom shutdown sequences in a Microsoft Access database.
- Observed behavior
- Access does not provide a global application-level BeforeClose event like Excel, making it difficult to control the exact sequence of form closures when the application is exited.
Before making structural or VBA changes to your forms, ensure you have backed up your current database file (.accdb or .mdb) to prevent accidental loss of code or data during testing.
Create Custom Navigation and Stop Buttons on Forms
Since Access cannot reliably intercept the main application close button natively, use custom form buttons to manually handle the closing sequence via VBA.
The most reliable workaround for the lack of an application-level event is to dictate how users navigate and exit your database. By providing specific 'Close' or 'Stop' buttons on your forms, you can execute a VBA script that closes forms in the exact order you require.
Right-click your target form in the Access navigation pane and select 'Design View'.
From the Form Design toolbar, select the Button control and place it on your form. Cancel the wizard if it appears.
Select the button, open the Property Sheet, go to the 'Event' tab, and click the ellipsis (...) next to 'On Click'. Choose 'Code Builder'.
In the VBA editor, write code to close the current form (e.g., DoCmd.Close acForm, Me.Name) and set focus to the previously opened form. Repeat this process for all forms to chain the closures in reverse order.

Subclass the Main Access Window using Windows API
For advanced users, intercept Windows messages sent to the Access application window to detect a close event.
Looking for a Lighter Alternative to Microsoft Office?
While Microsoft Access handles complex relational databases, for most everyday data tracking, document creation, and spreadsheet analysis, WPS Office provides a free, lightweight, and highly compatible alternative to the Microsoft Office suite. It loads quickly and features an intuitive, tabbed interface.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button.
- 2. Run the Installation: Open the downloaded installer file and follow the quick on-screen instructions.
- 3. Open Your Files: Launch WPS Office and immediately start opening or editing your existing Office files with full compatibility.

Frequently Asked Questions
Why doesn't Microsoft Access have a BeforeClose event like Excel?
Microsoft Access is structured differently than Excel. While Excel operates on individual workbooks within an application frame, Access is a complete database management system that handles events primarily at the individual form or report level (such as Form_Close or Form_Unload).
Can I loop through open forms in Access to close them?
Yes, you can loop through the AllForms collection in VBA. However, Access does not natively track the chronological order in which they were opened. To close them in reverse opening order, you must manually track their opening sequence using a custom VBA array, collection, or hidden tracking table.
How can I prevent users from closing Access using the main 'X' button?
You can prevent this by creating a hidden form that remains open while the database is running. In its Form_Unload event, you can cancel the unload process unless a specific public boolean variable (set by your custom 'Exit' button) is true.




