Office Settings & Configuration

How to Create a General Back Button for Microsoft Access Forms

Amos GikundaAmos Gikunda Nov 2, 2026 868 views

Question details

The user wants to create a reusable command button in Microsoft Access that dynamically returns them to the previously viewed form without writing unique code for every single form in the database.

How to Create a General Back Button for Microsoft Access Forms
Product
Microsoft Access
Device & OS
not provided
Scenario
Developing a multi-form database where users need a unified, generic navigation method to return to the last active form after completing a task or viewing details.
Observed behavior
Users mistakenly trigger DoCmd.GoToRecord , , acPrevious, which only navigates to the previous data record within the active form instead of opening the previously viewed form window.
Before you start

Ensure your database file is saved and create a backup copy before adding or modifying VBA modules, as errors in global variables can temporarily disrupt form navigation.

Solution 1Recommended

Create a Universal Back Button using VBA Global Variables

Store the name of the active form in a global variable before navigating away, then use a shared VBA function to call it back.

Many users mistakenly use 'DoCmd.GoToRecord , , acPrevious' thinking it will return them to the last opened form. However, this command is designed to navigate to the previous data record within the current form's recordset. To truly return to a previous form window, you must track form names programmatically.

By declaring a global variable in a standard module, you can store the name of the originating form just before opening a new one. A generic 'Back' button on your secondary forms can then trigger a public function to close the active form and reopen the stored form name.

1
Create a standard VBA module

Navigate to the 'Create' tab on the Access ribbon and click 'Module' to open the VBA editor. Declare a global variable at the top of the module by typing: Public strPreviousForm As String.

2
Write the navigation function

In the same module, write a generic function that closes the active form and opens the stored form. For example: Public Function GoBack(strCurrentForm As String) DoCmd.Close acForm, strCurrentForm DoCmd.OpenForm strPreviousForm End Function.

3
Update your form opening code

Whenever you use a button or event to open a new form, insert a line of VBA to set the global variable to the current form's name before the DoCmd.OpenForm action executes. Add: strPreviousForm = Me.Name.

4
Attach the function to your Back buttons

Open your secondary form in Design View, add a command button, and set its 'On Click' event to run the function: =GoBack([Form].[Name]). Copy this button to any form where you need generic back functionality.

Create a Universal Back Button using VBA Global Variables
Handling Hidden Forms: If your workflow hides the previous form instead of closing it, change the VBA code from 'DoCmd.OpenForm' to 'Forms(strPreviousForm).SetFocus' and ensure the hidden form's Visible property is restored to True.
Free Microsoft Office alternative

Looking for a lighter Office suite? Try WPS Office

While Microsoft Access is designed for complex relational databases, many data tracking and form-filling tasks can be efficiently managed using advanced spreadsheets. If you are looking for a highly compatible, lightweight, and free alternative to the standard Microsoft Office suite for your everyday document and data needs, WPS Office is an excellent choice.

  1. 1. Download WPS Office: Visit the official WPS website and click the free download button for your operating system.
  2. 2. Install the Software: Run the downloaded installer and follow the on-screen prompts to complete the setup in minutes.
  3. 3. Open Your Files: Launch WPS Spreadsheet to open your existing .xlsx data files and start organizing your records instantly.
Highly compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx) formats.Create robust data tracking spreadsheets with advanced data validation and forms as an alternative to complex databases.Free and lightweight suite covering Writer, Spreadsheet, Presentation, and PDF.Familiar user interface makes transitioning seamless with zero learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does DoCmd.GoToRecord return me to the previous record instead of the previous form?

The acPrevious argument in the DoCmd.GoToRecord method is specifically designed to navigate between data rows (records) within the active form's underlying table or query. It does not have any awareness of the form's window navigation history.

Can I use Access macros to create a general back button instead of VBA?

While you can use macros to close the current form and open a specific named form, creating a truly generic back button that dynamically remembers the previous form requires variables. Standard macros have limited support for passing global variables across forms, making VBA the more reliable choice for dynamic navigation.

What is the difference between closing a form and hiding it when navigating?

Closing a form completely removes it from memory and resets any unsaved, unbound data entries. Hiding a form keeps it loaded in the background, preserving its exact current state, filters, and user inputs. When returning to a hidden form, you must use SetFocus and make it visible again rather than reopening it.

Will this VBA back button work if multiple forms are open at the same time?

If you only use a single global variable (strPreviousForm), it will only remember the very last form that overwrote the variable. For complex applications where users can open multiple windows in varying orders, you would need to build a more advanced stack or array in VBA to track the complete, multi-level navigation history.