Applies ToAccess for Microsoft 365 Access 2024 Access 2021 Access 2019 Access 2016

If you want to run certain actions each time you open an Access database or an Access web app, create an AutoExec macro in a desktop database, or an On Start macro in an Access web app. For example, in a desktop database, an AutoExec macro could automatically maximize the application window, lock the Navigation Pane, and open a particular report each time you open the database.

In this topic

Create an AutoExec macro in a desktop database

An AutoExec macro (a macro that you name AutoExec) runs before any other macros or modules in the database. If you’ve already created a macro that does what you want to happen when the database starts, just rename the macro AutoExec, and it will run the next time that you open the database. Otherwise, follow these steps to create a macro:

  1. Click Create > Macro.The Macro button on the Create tab.

  2. In the drop-down list at the top of the Macro Builder, select the action that you want to perform. If applicable, type the appropriate values in the argument boxes.

    • If you can’t find the action you want, make sure Show All Actions is selected on the Design tab. This expands the list of actions that you can use, but the list will include some actions that will only run if the database is granted trusted status. For more information, see Decide whether to trust a database.

  3. Repeat step 2 for each additional action you want to occur. You can also search for actions in the Action Catalog and double-click or drag them into the macro.

  4. Click Save, and in the Save As dialog box, type AutoExec.

  5. Click OK and close the Macro Builder. The macro will run the next time you open the database.

For more information about how to create macros, see the article Create a user interface (UI) macro.

Notes: 

Top of Page

Create an On Start macro in an Access web app

An On Start macro in Access web apps performs the same sort of function as an AutoExec macro in a desktop database, but it does not appear in the Navigation Pane as a named macro. Also, instead of running when you open the database in the Access client, it runs when you open the web app in the browser. You can't bypass macro logic defined in an On Start macro when opening your web app in the browser.

Here’s how to create one:

  1. Open the web app in Access. If you are viewing it in a browser, click Settings > Customize in Access.

  2. Click Home > Advanced > On Start Macro.

    The On Start Macro command on the ribbon.

    Access opens the macro designer. If an On Start macro already exists, Access displays it. If not, you’ll see a blank macro where you can begin adding actions.

  3. Select actions from the Add New Action drop-down, or find actions in the Action Catalog and double-click or drag them into the macro.

    Tip: The Action Catalog displays short descriptions of the actions to help you learn what they do.

  4. If needed, enter values in the argument boxes for the actions you’ve added.

  5. Click Save > Close.

  6. Click Home > Launch App, and the On Start macro runs when the web app opens in the browser.

For more information about creating a macro in an Access web app, see Customizing a view by creating a user interface macro.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.