Share this Page URL

Chapter 13. Completing Your Database App... > Creating Macro Groups and Using Macr... - Pg. 461

Completing Your Database Application 461 When we set up an application switchboard form later in this chapter, we'll assign each of the macros in this group to an item on the form. Macro Conditions As we explained in Chapter 5, one reason to use Visual Basic rather than macros is that Visual Basic provides more ways to manage the logical flow of a database routine that you want to auto- mate. How-ever, you can define conditions for a macro to specify whether a macro or a particular macro action runs. The expression that defines a condition must evaluate to True or False: if it's True, the macro action runs; if it's False, the action is skipped. For example, you can enter a condition that tests whether a form is open. If the form is open, the macro will run. If the form is not open, the macro will not run. (You could use the IsLoaded function that comes with the Northwind Traders database as the basis for this condition. You'll find this function in the module modDemonstrations in the HelloWorld database and in the Northwind database.) If you want to run one macro action if a condition is true and another action if the condition is false, you need to enter these conditions and define the actions in separate rows in the Macro window. In the following steps, we'll add four macros to the SwitchboardForms macro group and define macro conditions that determine which actions these macros perform. When we set up the application switchboard, we'll use the macros for which we've defined conditions with two option groups. The actions the macros take depend on which options a user selects. See Also For more information about how to work with an option group, see Chapter 8, "Adding Fea- tures and Function to Forms." Define macro conditions 1. 2. 3. 4. 5. 6. If the SwitchboardForms macro isn't open in Design view, select the macro in the Database window, and then click Design. On the View menu, click Conditions. Skip a row after the CampaignReports macro. In the Macro Name column, enter Enable- CountryList. In the Condition column, enter the expression [ReportList] = 1. In the Action column, select SetValue. In the Action Arguments area, for the Item argument, enter [Country].[Enabled]. For the Ex- pression argument, enter No. The Macro window should look like the following: