Microsoft Access 2010 : Learning the Basics of Creating and Running a Macro (part 1) - Working with Macro Actions & Working with Action Arguments

10/10/2011 9:19:54 AM
To create a macro, click to select the Create tab. Then select Macro from the Macros & Code group. The Macro Design window shown in Figure 1 appears. In this window, you can build a program by adding macro actions, arguments, and program flow items to the macro.
Figure 1. The Macro Design window, showing the Action Catalog and the Macro Tools Design tab of the Ribbon.

Macro actions are like programming commands or functions. They instruct Access to take a specific action (for example, to open a form). Macro arguments are like parameters to a command or function; they give Access specifics on the selected action. For example, if the macro action instructs Access to open a form, the arguments for that action tell Access which form should be opened and how it should be opened (Form, Design, or Datasheet view, or Print Preview). Program flow items allow you to determine when a specific macro action will execute. For example, you might want one form to open in one situation and a second form to open in another situation.

Working with Macro Actions

As mentioned, macro actions instruct Access to perform a task. You can add a macro action to the Macro Design window in several ways. One way is to click in the macro item and then click to open the drop-down list. A list of all the macro actions appears, as in Figure 2. Select the one you want from the list, and it’s instantly added to the macro. Use this method of selecting a macro action if you aren’t sure of the macro action’s name and want to browse the available actions.

Figure 2. The Macro Action drop-down list, showing all the available macro actions.

After you have been working with macros for a while, you will know which actions you want to select. Instead of opening the drop-down list and scrolling through the entire list of actions, you can click a cell in the Action column and then start typing the name of the macro action you want to add. Access will find the first macro action beginning with the characters you type.

Drag and Drop Objects into Macros

The OpenTable, OpenQuery, OpenForm, OpenReport, and OpenModule actions are used to open a table, query, form, report, or module, respectively. These actions and associated arguments can all be filled in quite easily with a drag-and-drop technique:

Scroll through the Navigation Pane until you see the object that you want to add to the macro.

Click and drag the object you want to open over to the Macro Design window. The appropriate action and arguments are automatically filled in. Figure 3

shows the effects of dragging and dropping the Customer List form onto the Macro Design window.
Figure 3. The Macro Design window after the Customer List form was dragged and dropped on it.

Dragging and dropping a table, query, form, report, or module onto the Macro Design window saves you time because all the macro action arguments are automatically filled in for you. Notice in Figure 10.3 that six action arguments are associated with the OpenForm action: Form Name, View, Filter Name, Where Condition, Data Mode, and Window Mode. Three of the arguments for the OpenForm action have been filled in: the name of the form (Customer List), the view (Form), and the window mode (Normal). Macro action arguments are covered more thoroughly in the next section.

Working with Action Arguments

As mentioned, macro action arguments are like command or function parameters; they give Access specific instructions on how to execute the selected macro action. The available arguments differ depending on what macro action has been selected. Some macro action arguments force you to select from a drop-down list of appropriate choices; others allow you to enter a valid Access expression. Macro action arguments are automatically filled in when you click and drag a Table, Query, Form, Report, or Module object to the Macro Design window. In all other situations, you must supply Access with the arguments required to properly execute a macro action. To specify a macro action argument, follow these five steps:

Select a macro action.

If the macro action argument requires selecting from a list of valid choices, click to open the drop-down list of available choices for the first macro action argument associated with the selected macro action. Figure 4 shows all the available choices for the Form Name argument associated with the OpenForm action. Because the selected argument is Form Name, the names of all the forms included in the database are displayed in the drop-down list.

Figure 4. Available choices for Form Name argument.

If the macro action argument requires entering a valid expression, you can type the argument into the appropriate text box or get help from the Expression Builder. Take a look at the Where Condition argument of the OpenForm action, for example. After you click in the Where Condition text box, an ellipsis appears. If you click the ellipsis, the Expression Builder dialog box is invoked, as shown in Figure 5.

Figure 5. The Expression Builder dialog box enables you to easily add complex expressions to your macros.

To build an appropriate expression, select a database object from the list box on the left, and then select a specific element from the center and right list boxes. Click OK to accept the element into the text box. In Figure 10.5, the currently selected Expression Element is the Customer List form, Expression Category is Job Title, and <value> has been double-clicked to add the expression to the top half of the window. The value of Owner is entered in quotes indicating that the Job Title of each record displayed on the form must be Owner. Click OK to close the Expression Builder. The completed expression appears as shown in Figure 6.

Figure 6. The completed expression for the Where argument of the OpenForm action.

Remember that each macro action has different macro action arguments. Some of the arguments associated with a particular macro action are required, and others are optional. If you need help on a particular macro action argument, click in the argument and Access provides a tooltip with a short description of that argument. If you need more help, press F1 to see Help for the macro action and all its arguments.

- Microsoft Access 2010 : Deleting Records
- Microsoft Visio 2010 : Sharing Diagrams by Using the Visio Viewer
- Microsoft Visio 2010 : Creating Visio Templates
- Microsoft Word 2010 : Creating an XML Document
- Microsoft Word 2010 : Customizing Word - Linking and Embedding Files
- Microsoft PowerPoint 2010 : Saving a Presentation as a Slide Show & Saving a Presentation as a Video
- Microsoft PowerPoint 2010 : Delivering a Show on Multiple Monitors
- Getting Started with Microsoft Excel 2010 : Arranging Windows
- Getting Started with Microsoft Excel 2010 : Moving Around the Workbook
- Microsoft Outlook 2010 : Working with the Ribbon and the Backstage View
- Microsoft Outlook 2010 : Working in the Outlook Program Window
- Microsoft OneOnte 2010 : Creating Pages - Choose the Default Page Template for Section Pages
- Microsoft OneOnte 2010 : Creating Sections & Creating Section Groups
- Facilitating Your Plan with Microsoft Project 2010
- Microsoft Project 2010 : Understanding Project Management Basics
- Microsoft Access 2010 : Working with Table Data
- Microsoft Access 2010 : Working with an Existing Database
- Microsoft Visio 2010 : Sharing and Publishing Diagrams - Saving in Other File Formats
- Microsoft Visio 2010 : Sharing and Publishing Diagrams - Creating Graphics
- Microsoft Word 2010 : Customizing Word - Setting Editing Options
Most View
- Exchange Server 2013 : The Exchange Management Shell - Active Directory for PowerShell
- Adobe Dreamweaver CS5 : Working with Divs and AP Elements - Placing div Tags (part 1)
- Windows 8 for Business : Disk Encryption - EFS, BitLocker and BitLocker To Go
- Microsoft Project 2010 : Viewing Baselines (part 2) - Formatting the Gantt Chart to Display the Baseline
- SQL Server 2012 : Delivering Manageability and Performance (part 4) - POLICY-BASED MANAGEMENT - SQL Server — Max Degree of Parallelism
- Microsoft Visio 2010 : Introducing Automation and VBA Code (part 2) - Using the Macro Recorder to Generate Code
- Exchange Server 2013 : Defining a Highly Available Messaging Solution - Achieving High Availability
- Active Directory 2008 : Configuring Replication (part 3) - Intersite Replication - Creating Connection Objects , Moving Server Objects between Sites
- Windows 8 : Sharing and Securing with User Accounts - Using User Accounts (part 2) - Turning UAC on and off
- Windows Phone 8 : Receiving Input with Buttons - Repeat and Toggle Buttons
Top 10
- Microsoft Sharepoint 2013 : Administering Sharepoint with Windows Powershell - Basic PowerShell Usage (part 3) - Controlling Output
- Microsoft Sharepoint 2013 : Administering Sharepoint with Windows Powershell - Basic PowerShell Usage (part 2) - PowerShell Help , PowerShell Variables
- Microsoft Sharepoint 2013 : Administering Sharepoint with Windows Powershell - Basic PowerShell Usage (part 1) - Listing the SharePoint Commands
- Microsoft Sharepoint 2013 : Administering Sharepoint with Windows Powershell - Commands
- Microsoft Sharepoint 2013 : Microsoft SharePoint 2013 Management Shell and Other Hosts
- Microsoft Word 2010 : Using Advanced Text Features - Addressing Envelopes
- Microsoft Word 2010 : Using WordArt (part 2) - Changing the Format of a WordArt Object
- Microsoft Word 2010 : Using WordArt (part 1) - Inserting WordArt Text
- Microsoft Word 2010 : Creating and Formatting Text Boxes (part 3) - Formatting Text in a Text Box, Linking Text Boxes
- Microsoft Word 2010 : Creating and Formatting Text Boxes (part 2) - Resizing a Text Box , Moving a Text Box