logo
search
Office Settings & Configuration

How to Close Access Forms in Reverse Opening Order

Kushani NimanthikaKushani Nimanthika Oct 10, 2026 869 views

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.

How to Close Access Forms in Reverse Opening 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 you start

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.

Solution 1Recommended

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.

1
Open the form in Design View

Right-click your target form in the Access navigation pane and select 'Design View'.

2
Add a Command Button

From the Form Design toolbar, select the Button control and place it on your form. Cancel the wizard if it appears.

3
Assign VBA Code to the On Click Event

Select the button, open the Property Sheet, go to the 'Event' tab, and click the ellipsis (...) next to 'On Click'. Choose 'Code Builder'.

4
Write the custom closing script

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.

Create Custom Navigation and Stop Buttons on Forms
Application Level Limitation: To force users to use your custom buttons, you may need to hide the main application Close button or restrict default Access menus.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and click the free download button.
  2. 2. Run the Installation: Open the downloaded installer file and follow the quick on-screen instructions.
  3. 3. Open Your Files: Launch WPS Office and immediately start opening or editing your existing Office files with full compatibility.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Lightweight installation that consumes minimal system resources compared to traditional suites.Built-in PDF reader and editor for seamless document management.Familiar, user-friendly interface that requires zero learning curve.
microsoft office alternative - wps office

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.