Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


1060


To implement a macro using submacros, create a form (frmMainMenu) with three buttons — in
this case, cmdContacts, cmdProducts, and cmdSales. Then set the On Click event proper-
ties of these buttons as follows (see Figure 30.8):

Button name On Click event property

cmdContacts mcrMainMenu.OpenContacts
cmdProducts mcrMainMenu.OpenProducts
cmdSales mcrMainMenu.OpenSales

FIGURE 30.8

The submacro names appear after the macro object in the event property drop-down list.


Main macro name

Submacro name

Open frmMainMenu in Form view and click the Contacts button; frmContacts opens and dis-
plays all the records. Click the Products button to display frmProducts, which only displays one
record. Click the Sales button to display frmSales in a minimized state, which displays the sales
made in 2012.

To see why these forms open differently, take a look at the action arguments for the OpenForm
action:

l (^) Form Name: This argument is the name of the form you want the macro to open.
l View: This argument lets you select which view to open the form in: Form, Design, Print
Preview, Datasheet, PivotTable, PivotChart, or Layout. For this example, frmContacts
and frmProducts open in Form view, while frmSales opens in Layout view.
l (^) Filter Name: This argument lets you select a query or a filter saved as a query to restrict
and/or sort the records for the form. For this example, this argument is set to qry-
Sales2012 for the OpenSales macro. qrySales2012 is a query that outputs all the
fields in the table and only displays sales between 1/1/2012 and 12/31/2012. This query
also sorts the records by SaleDate.

Free download pdf