06Jan2015

Microsoft Access – How to run a macro when database opens?

Microsoft Access allows the users perform a set of actions every time a database loads or opens by creating a macro called ‘AutoExec’. You can run a macro when database opens by naming it as ‘AutoExec’ or calling the ‘AutoExec’ macro.

As the name suggests, an ‘AutoExec’ macro is a macro that automatically executes the actions we specify when a database opens. If you name a macro as ‘AutoExec’, it executes on database load.

Create an AutoExec macro

Let us say, you want a form to be opened whenever you open the database. So, create a form with name, say, ‘Main Dashboard’. Add a few buttons just to give it a feel of an Access form. Save and close the form. This is how the form looks like

Autoexec - run a macro when database opens

 

To create a macro, go to ‘Create’ tab in the ribbon and click on the ‘Macro’ icon as shown below.

Autoexec macro - run a macro when database starts

It opens a new window. For the ‘Action’ attribute, click on the dropdown to expand the list of options and select ‘Open Form’ as we want to open a form whenever database is loaded/opened.

Arguments will be populated automatically. In the action attributes section, select the form name as ‘Main Dashboard’ as this is the form we want to open on database load.

Autoexec macro - run a macro when access database opens

 

Save the macro by giving the name ‘Autoexec’ and close it. Also close the database and re-open it.

On opening of the database, we will see the access form ‘Main Dashboard’ opened. Below is image you will see on opening the database. This is what AutoExec does. It performs the actions that we specify whenever the database opens.

Autoexec macro - database open

Now, what if you already have a macro written with a specific set of actions and you want it to execute every time database opens.

You have two options. You can either rename that macro with name ‘Autoexec’ so that it runs whenever database starts or create an ‘Autoexec’ macro and select ‘Run Macro’ as Action and call the macro you already have with the set of actions. Sounds interesting?

Contact us if you have any questions on Microsoft Access. Excel for Commerce would be happy to help you.

 

 

  • 6 Jan, 2015
  • Excel for Commerce
  • 0 Comments
  • Access, AutoExec,

Categories

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *