Case Example


Earlier in this chapter, you learned how to automate actions by using macros. In this example, you'll use a macro group to help you create command buttons that open sets of records in a form. Specifically, you'll create buttons on an orders form to filter for regular delivery and overnight orders. This exercise also exposes you to creating and using command buttons. I haven't discussed command buttons separately, but (as you'll see) you shouldn't have any trouble figuring them out on your own.

First, let's create the macro group:

1.

In the Database window, click the Macros tab and click New.

2.

Choose View, Macro Names. The Macro Names column is displayed. You toggle the Macro Names column on and off by choosing View, Macro Names.

3.

In the first row of the Macro Names column, type yes. Press Tab.

4.

In the Action column, open the drop-down list and choose ApplyFilter. Press Tab.

5.

In the Comment column, type Filter for overnight clients.

6.

In the Where Condition of the action arguments, type [Overnight]=yes.

This is an expression that creates criteria for the action. It tells Access to select those records whose value is Yes in the field Overnight.

7.

In the third row, click in Macro Name and type no. Press Tab.

8.

In Action, open the drop-down list and choose ApplyFilter. Press Tab.

9.

In Comment, type Filter for regular delivery.

10.

Click in Where Condition. Type [Overnight]=no.

11.

In the fifth row, click in Macro Name and type all. Press Tab.

12.

In Action, type sh to choose ShowAllRecords. Press Tab. Note that no action arguments are available for this action.

13.

In Comment, type Shows both overnight and regular delivery records. Your macro should look like Figure 12.46.

Figure 12.46. A group macro contains several macros, each with their own names.


14.

Save the macro group. Type mcrDeliveryMethod and click OK.

15.

Close the group macro.

Now you'll create command buttons on the form to filter for regular delivery and overnight orders. You'll also include a button to show all records.

1.

Open the frmOrdersMacro form in Design view.

2.

Click the Command Button tool (it's in the last column and fourth row of the toolbox). Move the pointer 3 inches from the top and 0.5 inch from the left, and click.

3.

In the Command Button Wizard, click Miscellaneous in the left pane. Click Run Macro in the right pane. Click Next.

In this dialog box, you determined the action of the command button.

4.

Choose mcrDeliveryMethod.no and click next.

In this dialog box, you selected the appropriate macro. The macro name comprises the group macro name and the individual macro.

5.

Click Text. Highlight Run Macro and type Regular; click Next.

In this dialog box, you put text on the button to identify it in the form.

6.

Name the button RegularDelivery. Click Finish.

Now you'll create the two other buttons for retrieving orders.

7.

Click the Command Button tool. Move the pointer 3 inches from the top and 1.5 inches from the left, and click.

8.

In the Command Button Wizard, click Miscellaneous in the left pane.

Click Run Macro in the right pane. Click Next.

9.

Choose mcrDeliveryMethod.yes and click Next.

10.

Click Text. Highlight Run Macro and type Overnight. Click Next.

11.

Name the button OvernightDelivery. Click Finish.

12.

Click the Command Button tool. Move the pointer 3 inches from the top and 2.5 inches from the left, and click.

13.

In the Command Button Wizard, click Miscellaneous in the left pane.

Click Run Macro in the right pane. Click Next.

14.

Choose DeliveryMethod.all and click Next.

15.

Click Text. Highlight Run Macro and type All Orders. Click Next.

16.

Name the button AllOrders. Click Finish.

17.

Choose File, Save to save your changes. Your Design window should look similar to Figure 12.47.

Figure 12.47. The command buttons in Design view.


18.

Click View to switch to Form view.

Try out the various filter buttons you created. The Overnight records should have a check in the Overnight check box. There are 33 total orders, of which 2 were shipped overnight.

19.

Choose Records, Remove Filter/Sort to remove any filters you applied.

20.

Close the form and close your database.

You can compare any of the objects you created in this chapter to those in NiftyLionsChap12End.mdb.




Hands-On Microsoft Access(c) A Practical Guide to Improving Your Access Skills
Hands-On Microsoft Access: A Practical Guide to Improving Your Access Skills
ISBN: 0321245458
EAN: 2147483647
Year: 2005
Pages: 169
Authors: Bob Schneider

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