Microsoft Access 2010 tutorial:Create macro condition


Create macro condition

III. Create macro condition

In the previous section, you learn how to create a stand-alone macro, macro group and an embedded macro, but don't you know yet how to create a macro including the condition(s). Macro condition is really important because you can specify what you want the macro to run or to display. For example, you have the ProductByCategory form as figure below:

Access product by category form

Through this form, you can print the product report by category. If you want to print a report that contains all products in Cate001, you just click the Print Report button because the form is displaying Cate001 with its products. After you clicked the Print Report button, the form will print the report only with the products in this category. See the figure:

Access report product by category 

If you want to print the report that contains Cate002 or Cate003 or other categories with its products, move the record to any category you want to print and then click the Print Report button.

To make the form can perform the actions above, you need to create a master detail report and a macro including a condition as the following:

+ Create the master detail report as the figure below:

Access product by category master detail report 

If you don't know how to create the master detail report, read this page: Create master detail report

+ Create the macro with condition:

- Click Create tab

- Click Macro in the Macro & Code group

- Fill in the required information of the macro as the figure:

Access macro condition

- Save the macro as MaCondition

- Open the ProductByCategory form in Design view and connect the macro with the Print Report button on this form. To connect the macro with the command button, click the command button, then click Event tab of the Property Sheet, next, click drop-down arrow in front of On Click event property, and lastly, click MaCondition. See the figure:

Access use macro condition with button 

- Click Save and then click View to view the Form

- Click Print Report button to test the macro condition

 


Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.