Microsoft Access VBA Programming for the Absolute Beginner

Let’s assume we want to build a report of our customer list grouped by state and then by zip code within the state. First, open the Report Wizard by selecting the Create Report By Using Wizard option in the Reports Objects window. Then select tblCustomer as the data source, and use all the columns, as shown in Figure 13-3.

Figure 13-3: Step one of the Report Wizard

The next step, after clicking Next, allows you to decide the grouping. In this case, as shown in Figure 13-4, txtState is selected, with txtZipCode as the subgrouping. Within the groupings, you can do a sort on last name by selecting Next and then the txtCustLastName column and leaving the sort order as Ascending, as shown in Figure 13-5.

Figure 13-4: Step two: grouping the data

Figure 13-5: Using the wizard to build a sort within the groupings

The next screen allows you to select a style. For this report, Stepped works nicely. The step after that allows you to select the format style. This example uses Corporate.

The final screen is where you select a name for the report. As mentioned earlier, this is also the title of the report. You can convert the name to proper format later on. For the time being, let’s use the name Customer List. After selecting Finish in the title screen, the report should look like Figure 13-6.

Figure 13-6: Finished report created in Report Wizard

You can see how easy it is to build a nice report with groupings. However, there are some problems. Some of the labels are too wide, and the customer number falls between the last and first name. From here on, you can easily go into Design View and make some adjustments, as shown in Figure 13-7. The finished result is shown in Figure 13-8.

Figure 13-7: Adjustments in Design View

Figure 13-8: Adjusted report

As you can see, you need knowledge of both AutoReport and the wizard. Go to the Database window now, and change the name of the report to rptCustomer. At this stage, the title on the report, Customer List, will not be changed.

Категории