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:
-
Click Create > Macro.
-
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.
-
-
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.
-
Click Save, and in the Save As dialog box, type AutoExec.
-
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:
-
To bypass the AutoExec macro and other startup options, hold down the SHIFT key while you start the database. For more information, see Bypass startup options when you open a database.
-
Another way to perform actions when a database starts is to specify a startup form and attach macros or VBA code to the OnOpen or OnLoad events of the form. For more information, see the article Set the default form that appears when you open an Access database.
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:
-
Open the web app in Access. If you are viewing it in a browser, click Settings > Customize in Access.
-
Click Home > Advanced > On Start Macro.
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.
-
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.
-
If needed, enter values in the argument boxes for the actions you’ve added.
-
Click Save > Close.
-
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.