Create macros in Microsoft Access to automate tasks. Access allows you to create two macros in two different ways. The first requires you to know Visual Basic programming, while the second allows you to create macros in a table format. Both are extremely useful and can save valuable time for both you and your Access users.
Visual Basic Macro
The first macro you can create is created in Visual Basic. Go to the “Tools” menu and select Visual Basic Editor. You must know Visual Basic code in order to create macros this way. You can automate most database tasks, including those within the database. However, most users prefer to use the second macro creation method to create macros. For complete control over your macros, use this method.
For assistance with creating Visual Basic macros, access the Help menu while in the Visual Basic editor. This menu will help you with terms and code.
In the main database window, open the Macros section. Press the New button to create a new macro. By default, the only columns available are Actions and Comments. However, if you want to create nested macros or use conditions, press the Conditions and Macro Name buttons on the macro toolbar to add these columns to the Macro window.
The macro name column is a text only column for naming your macro. You can have multiple macros within a single main macro. Naming your macro allows you to have multiple actions within a single macro name. This makes troubleshooting and editing later if each group of actions has a separate macro name.
The conditions column is for creating certain conditions under which your macro will run. The condition may apply to the entire macro or a specific portion of your macro. Conditional expressions often include where or like clauses.
The action column is the most important column in your Access macro. This is where all the action actually takes place. Choose an action from the drop down menu. Once an action is selected, a list of criteria and options appears at the bottom of the screen, when available. The criteria vary greatly based upon your action. For instance, the GoToControl action only requires you to choose the Control Name, while the OpenForm action asks for the Form Name, View type, Window Mode and other optional criteria.
The comment column can also be important when troubleshooting or understanding a macro. The larger a macro becomes, the more difficult it can be to remember the purpose of each portion of the macro. The comment column allows you to add a description of the macro or action’s purpose, such as specifying the name of the form you open or which application a report is sent to.
Once a macro is created, press the Run button on the macro toolbar to test it. The Run button looks like a red exclamation point. Please test macros on a copy of your database, especially if your macro adds, edits or deletes information.
If you want to run multiple macros from within a single macro, create each macro, or group of nested macros, separately. Once each set is created, create a master macro. The only actions in your master macro should be RunMacro with the desired macro names. Create a new row with the RunMacro action for each macro you wish to run. When you run the master macro, all other macros contained within it will run in the order specified.