Getting to Know Microsoft Access, Part 9: Macros - Macros
(Page 2 of 4 )
A macro is essentially a list of actions that you apply to objects to respond to events. Each action carries out one task. You create your actions in the order you want them to execute. In addition, you specify the arguments of the actions, giving the program additional information as needed.
Finally, you can set conditions for each action in a macro to determine whether it runs or not. Run a macro by applying it to the event property of an object. Once the specified event occurs the macro will run by running the all the specified actions. Actions that have conditions applied to them may or may not run depending on whether or not they passed the conditional tests.
Once you've created your macros you'll see them listed in the Macros tab in the Database window. This way you can attach any macro to any event property in your database.
Creating Your First Macro
As in any programming endeavor it is helpful to first design your macro before you build it. To do this, list the actions you want to occur, and in what order you want them to occur. Also describe the event you want the macro to apply to. Check the Access help feature to determine if the macro you are building is right for the event property you are planning to apply it to. Determine in advance which arguments each action will have and whether it will be conditional or not. What are the conditions? What are the arguments? You should sort out all these details before you start building your macro. Use pseudocode if you know it.
To build your first macro, click "New" in the Macros tab of the Database window. Here's what the Create New Macro window looks like:

Select your first action from the Actions column in the Macro window. Remember to put in a comment so you remember what the action is for. When you select your first action the arguments pane opens up below. You can either type in the arguments you want, or select from what is available in the drop-down lists. Current arguments are displayed to the right of the argument pane.
If the argument requires an object name you can either type in the name or drag it from the Database window. Finally, you can set the argument to an expression that evaluates to the desired argument value. For instance, you could type in =[LastName] to set the argument value to the LastName control. The Expression Builder (click the Build… link) helps you build your expressions; not all arguments accept expressions.
Next: Debugging >>
More Microsoft Access Articles
More By Sage Adams