databasedev.co.uk - database solutions and downloads for microsoft access

Microsoft Access Macros

AutoExec Macro in Microsoft Access

In Microsoft Access you can use startup options to specify, for example, what form to display, whether toolbars can be customized, and whether shortcut menus are available in your Microsoft Access file.

You can also use a special macro named AutoExec to carry out an action or series of actions when your database first opens. When you open a database, Microsoft Access looks for a macro with this name and, if it finds one, runs it automatically.

Running a Macro Automatically when Starting Microsoft Access:

If you want to open a particular form, for example a switchboard form, when opening Microsoft Access, you will need to create the macro. To create an AutoExec macro, that opens a form, follow the steps listed:

  1. Create a new macro (we will name this AutoExec later)
  2. Type in OpenForm, or select the action from the list, in the Action cell
  3. Type in the name of the form, (or choose the switchboard form name) in the form name cell in the Action Arguments pane:

    Creating the AutoExec macro.
    Creating the AutoExec macro.
  4. Save the macro, ensuring that it is named exactly as AutoExec.

After you perform these actions, Microsoft Access will run the macro automatically when the database is opened.

Controlling Options when Starting Microsoft Access

In Microsoft Access 2000 and later, rather than use the AutoExec macro, you can use the startup form to control many options, including:

  • Specify an icon to use when Access is minimized
  • Change the Title Bar text
  • Global Custom Menu Bar
  • Global Custom Shortcut Bar
  • Display a form on startup
  • Controlling the display of default menus, toolbars, the database window and the status bar

Showing the Startup options dialog box available in Microsoft Access 2000 onwards.
Showing the Startup options dialog box available in Microsoft Access 2000 onwards.

See more on The Autoexec macro in Microsoft Access over at vb123.com