Create a macro that runs when you open a database

If you want to perform a particular set of actions every time that a database starts, you can create an AutoExec macro. For example, when the database starts, you might want to automatically maximize the application window, lock the Navigation Pane (Navigation Pane: The pane that appears when you open an Access database or an Access project. The Navigation Pane displays the objects in the database, and can be customized to sort and group objects in different ways.), and then open a particular report.

An AutoExec macro is just a macro that is named AutoExec. When a database starts, Access runs the AutoExec macro before it runs any other macros or VBA code (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.).

 Important   AutoExec macros are not compatible with the Publish to Access Services feature. If you add an AutoExec macro to a web database, you will no longer be able to publish or synchronize the database with Access Services.

Create an AutoExec macro

If you have already created a macro that contains the actions that you want to occur 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. On the Create tab, in the Macros & Code group, click Macro.

    Ribbon image
  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 cannot find the action you want, on the Design tab, in the Show/Hide group, make sure Show All Actions is selected. 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 the article Decide whether to trust a database.
  1. Repeat step 2 for each additional action that you want to occur.
  2. Click Save, and in the Save As dialog box, type AutoExec.
  3. Click OK and then close the Macro Builder. The new macro will run the next time that you open the database.

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


Top of Page Top of Page

Applies to:
Access 2010