Lesson10.3.Working with Macro Groups


Lesson 10.3. Working with Macro Groups

Figure 10-4. Two macrosthe Open frmEmployees macro and the Print rptEmployeeSales macrowithin a single macro group.


Figure 10-5. The Run Macro dialog box.


If you are creating lots of macros, you might want to consider organizing them into a macro group to help you manage them. A macro group stores several related macros together in a single macro object. When you create a macro group, you must give each macro in the macro group its own unique name to identify where each macro starts and ends. You do this by entering the macro names in the Macro Name column, which you display by clicking the Macro Names button on the toolbar.

When you combine two or more macros within the same macro group, you must run them separately, by referring to the macro group name, followed by the macro name. For example, mcrEmployees. mcrEmployees frmEmployees refers to the Open frmEmployees macro in the mcrEmployees macro group.

In this lesson you will learn how to group several related macros together in a macro group.

  1. Select the mcrEmployees macro and click the Design button.

    In order to work with macro , you need to display the Macro Name column.

  2. Click the Macro Names button on the toolbar.

    First you need to give the macro you created in the previous two lessons a name. The cursor is already positioned in the Macro Name cell of the first row.


    Note: Always enter the macro name in the Macro Name column, next to the Action where the macro starts.

  3. Type Open frmEmployees in the first blank cell in the Macro Name column.

    The macro name "Open frmEmployees" identifies the macro you created in the previous two lessons. To create another macro in the same macro group, type its name in the Macro Name column next to the first action of the new macro.

  4. Press the key three times.

    Type Print rptEmployeeSales.

    "Print rptEmployeeSales" is the name of the new macro we will create.

  5. Click the Action cell to the right of the Print rptEmployeeSales macro name, click the list arrow, scroll down, and select OpenReport.

    Similar to the OpenForm action, which opens a form, the OpenReport action opens a report. Next, you need to specify the arguments for the OpenReport action.

  6. Click the Report Name text box in the Action Arguments panel, click the list arrow, and select rptEmployeeSales.

    This macro will open the rptEmployeeSales report. Notice Print appears in the View argument boxthis will send the rptEmployeeSales report directly to the printer. Let's add a comment to this new macro.

  7. Click the blank Comment box in the Print rptEmployeeSales macro row and type This macro prints the rptEmployeeSales report.

    You want to add one more action to the Print rptEmployeeSales macro.

  8. Click the Action cell just below the OpenReport action, click the list arrow, scroll down, and select MsgBox.

    You need to tell Access what you want the message box to say.

  9. Click the Message argument box and type The Employee Sales report has been sent to the printer.

    Let's specify several additional arguments for the MsgBox action, such as the type of icon that is displayed in the message box.

  10. Click the Type argument box, click the list arrow, and select Information. Click the Title argument box and type Notice.

    Your macro should look like the one shown in Figure 10-4.

  11. Click the Save button on the toolbar and close the macro window.

    Let's test our new macro. When you combine several macros within the same macro group you must run them separately using the Tools command on the Access menu.


    Note: Don't run a macro group by double-clicking it or selecting it and clicking Run. Doing so will run every macro in the macro groupoften with disastrous results!

  12. Select Tools The Run Macro dialog box appears, as shown in Figure 10-5. Here's where you select the specific macro you want to run.

  13. Click the Macro Name list arrow, select mcrEmployees.Open frmEmployees, and click OK.

    Access runs the Open frmEmployees macro.

  14. Click OK to close the message box and close the frmEmployees form.

If you want, go ahead and repeat Step 13 and run the Print rptEmployeeSales macro. Make sure your computer is connected to a printer, as this macro will send a copy of the rptEmployeeSales report to the printer.

QUICK REFERENCE

TO CREATE A MACRO GROUP:

  1. CREATE A NEW MACRO OR EDIT AN EXISTING MACRO.

  2. CLICK THE MACRO NAMES BUTTON ON THE TOOLBAR.

  3. TYPE THE MACRO NAME IN THE MACRO NAME COLUMN NEXT TO THE ACTION WHERE THE MACRO STARTS.

  4. IF NECESSARY, ADD THE MACRO ACTIONS OR EDIT THE EXISTING MACRO ACTIONS.

  5. SAVE THE MACRO AND CLOSE THE MACRO WINDOW.

TO RUN A MACRO IN A MACRO GROUP:

  1. SELECT TOOLS

    CLICK THE MACRO NAME LIST ARROW, SELECT THE MACRO YOU WANT TO RUN, AND CLICK OK.




CustomGuide Inc - Access 2003 Personal Trainer
Access 2003 Personal Trainer (Personal Trainer (OReilly))
ISBN: 0596009372
EAN: 2147483647
Year: 2005
Pages: 209

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net