MS Access

Review: Creating and Running a Macro

To Create a Macro: In the database window, click the Macros icon in the Objects bar and click the New button. Click the first blank Action cell, click the list arrow, and select the action you want the macro to perform.

Specify any required arguments for the action in the Action Arguments area. Repeat for each additional action you want the macro to execute. Click the Save button on the toolbar, give your new macro a name, and click OK.

To Run a Macro: Click the Macros icon in the Objects bar and double-click the macro you want to run.

Editing a Macro

  • To Modify a Macro: In the Database window, click the Macros icon in the Objects bar, select the macro you want to edit, and click the Design button.

Working with Macro Groups

  • To Create a Macro Group: Create a new macro or edit an existing macro, then click the Macro Names button on the toolbar. Type the macro name in the Macro Name column next to the action where the macro starts. If necessary, add the macro actions or edit the existing macro actions. Save the macro and close the macro window.

  • To Run a Macro in a Macro Group: Select Tools » Macro » Run Macro from the menu, click the Macro Name list arrow, select the macro you want to run, and click OK.

Assigning a Macro to an Event

  • To Assign a Macro to a Control on a Form or Report: Open the form or report in Design view, click the control to which you want to assign the macro and click the Properties button on the toolbar. Click the Event tab, click in the box for the type of event you want to assign to the macro, then click the list arrow and select the macro you want to assign to the event. Close the Properties dialog box and save the form or report.

Creating Conditional Expressions

  • To Create a Conditional Expression in a Macro: Create a new macro or edit an existing macro. In Design view, click the Conditions button on the toolbar and click the Condition cell next to the action you want to evaluate. Enter the conditional expression in the Condition cell, using proper Access syntax. You can use the Expression Builder to help you create the expression by clicking the Build button on the toolbar. Repeat these steps for each action you want to evaluate. Save the macro and close the macro window.

Assigning a Macro to a Keystroke Combination

  • To Assign a Macro to a Keystroke Combination: Create a macro group named AutoKeysthis will store all the macros that are assigned to a keystroke combination. Click the Macro Names button on the toolbar. Type the keystroke combination in SendKey syntax in the Macro Name column next to the Action where the macro starts.

Quiz

  1. The fastest and easiest way to create a macro in Microsoft Access is with the Macro Recorder. (True or False?)

  2. A(n) ___, or command, is the basic building block of a macro.

    1. Expression.

    2. Action.

    3. Procedure.

    4. Function.

  3. Macros may contain more than one action to perform several steps in sequence. (True or False?)

  4. Which of the following statements is NOT true?

    1. You can add an optional comment to a macro action in the Comment column.

    2. You use arguments to supply Microsoft Access with information about how to carry out specific actions.

    3. A macro group stores several named macros together in a single group.

    4. To run a specific macro in a macro group, double-click the macro, select the specific macro from the list, and click Run.

  5. Which of the following columns cannot be found in the Macro Design window?

    1. Macro Name column (if the Macro Names button on the toolbar is selected).

    2. Action Arguments column.

    3. Condition column (if the Conditions button on the toolbar is selected).

    4. Action column.

  6. You can assign a macro to a button, so that when a user clicks the button or control, a macro is activated. The procedure for doing this is:

    1. (1) Open the form in Design View, (2) select the button and display its properties, (3) click the Event tab and click the On Click box, (4) click the down arrow and select the macro you want to assign to the button.

    2. (1) Open the macro in Design View, (2) select the form and button you want to assign the macro to from the Assign box, (3) click Event box, click the down arrow and select On Click from the list.

    3. (1) Open the form in Design View, (2) select the button, and (3) select the macro from the Macro List on the toolbar.

    4. Too lengthy and complicated to be described in a brief quiz question.

  7. Conditions only effect the corresponding Action row in the macrothe other actions in the macro will execute without being evaluated. If you want to evaluate the other actions, they must each have their own statement in the Condition column. (True or False?)

Homework

  1. Open the Homework database.

  2. Create a macro named "OpenReport" that opens the Insurance Claims by Date report in Print Preview. Try running this macro.

  3. Modify the OpenReport macroadd a conditional expression so that the OpenReport action won't execute if the Score field in the Test Answers form equals an "F." Hint: Use the Expression Builder if you need help creating the conditional expression.

  4. Add another conditional action to the OpenReport macroone that displays a message box that says "Sorry, you failed!" if the Score field in the Test Answers form equals an "F."

  5. Open the Test Answers form in Design View.

  6. Add a command button to the form whose On Click event property runs the OpenReport macro.

  7. Save the Test Answers form, display it in Form View, and test the command button.

  8. Close the Homework database.

Quiz Answers

  1. False. Microsoft Excel and Word both have macro recorders you can use to create macros, but with Microsoft Access, you create macros in the Macro Design window.

  2. B. An action is the basic building block of a macro.

  3. True. Macros can contain multiple actions to automate several steps in a sequence.

  4. D. Double-clicking a macro group will run every named macro in the group, often with disastrous results.

  5. B. This was a trick question. Macro actions do have arguments; however, they can be found in the Action Arguments panelnot in a column.

  6. A. The correct procedure for assigning a macro to a button is: (1) Open the form in Design View, (2) select the button and display its properties, (3) click the Event tab and click the On Click box, (4) click the down arrow and select the macro you want to assign to the button.

  7. True. Conditions only effect the corresponding Action row in the macro. If you want to evaluate the other actions, they must each have their own statement in the Condition column.

by BrainBellupdated
Advertisement: