[ Team LiB ] |
![]() ![]() |
Building Reports Based on More Than One TableThe majority of reports you create will probably be based on data from more than one table. This is because a properly normalized database usually requires that you bring table data back together to give users valuable information. For example, a report that combines data from a Customers table, an Orders table, an Order Details table, and a Product table can supply the following information:
You can base a multitable report directly on the tables whose data it displays, or you can base it on a query that has already joined the tables, providing a flat table structure. Creating One-to-Many ReportsYou can create a one-to-many report by using the Report Wizard, or you can build a report from scratch. Different situations require different techniques, some of which are covered in the following sections. Building a One-to-Many Report by Using the Report WizardBuilding a one-to-many report with the Report Wizard is quite easy. You just follow these steps:
The report created in this example is shown in Figure 17.17. Notice that the report is sorted and grouped by Country, City, and OrderID. The report's data is in order by ProductName within an OrderID grouping. Figure 17.17. A completed one-to-many report.This method of creating a one-to-many report is by far the easiest. In fact, the "background join" technology that the wizards use when they allow you to pick fields from multiple tables—figuring out how to build the complex queries needed for the report or form—is one of the major benefits of using Access as a database tool. It's a huge timesaver and helps hide unnecessary complexity from you as you build a report. Although you should take advantage of this feature, it's important that you know what's happening under the covers. The following two sections give you this necessary knowledge. Building a Report Based on a One-to-Many QueryA popular method of building a one-to-many report is from a one-to-many query. A one-to-many report built in this way is constructed as though it were based on the data within a single table. First, you build the query that will underlie the report (see Figure 17.18). Figure 17.18. An example of a query underlying a one-to-many report.When you have finished the query, you can select it rather than select each individual table (as done in the previous section). After you select the query, you follow the same process to create the report as described in the preceding section. Building a One-to-Many Report with the SubReport WizardYou can build a one-to-many report by building the parent report and then adding a SubReport control. This is often the method used to create reports such as invoices that show the report's data in a one-to-many relationship rather than in a denormalized format. If you want to use the SubReport Wizard, you must make sure that you select the Control Wizards tool before you add the SubReport control to the main report. Here is the process:
As you can see in Figure 17.21, the one-to-many relationship between two tables is clearly highlighted by this type of report. In the example in Figure 17.21, each customer is listed. All the detail records reflecting the orders for each customer are listed immediately following each customer's data. Figure 17.21. A one-to-many report created with the SubReport Wizard.Working with SubreportsWhen you add a subreport to a report, it's important to understand what properties the SubReport Wizard sets so that you can modify the SubForm/SubReport control, if needed. Subreport PropertiesYou should become familiar with the properties of a SubForm/SubReport control, which are described in the following sections (see Figure 17.22). Figure 17.22. Properties of the SubForm/SubReport control.Source ObjectThe Source Object control specifies the name of the report or other object that's being displayed within the control. Link Child FieldsThe Link Child Fields control specifies the fields from the child report that link the child report to the master report. Link Master FieldsThe Link Master Fields control specifies the fields from the master report that link the master report to the child report. Modifying SubreportsNot only should you know how to work with the properties of a SubForm/SubReport object, but you should also be able to easily modify the subreport from within the main report. You can always modify the subreport by selecting it from the list of reports in the Database window. To do this, you select the report you want to modify and then click Design. You can also modify a subreport by selecting its objects directly within the parent report. ![]() |
[ Team LiB ] |
![]() ![]() |