Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Building Reports Based on More Than One Table


The 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 your 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:

  • Customer information :
    company name and address

  • Order information :
    order date and shipping method

  • Order detail information :
    quantity ordered and price

  • Product table :
    product description


You can base a multitable report directly on the tables whose data it displays, or on a query that has already joined the tables, providing a flat table structure.

Creating One-to-Many Reports


You can create one-to-many reports by using a Report Wizard, or you can build the report from scratch. Different situations require different techniques, some of which are covered in the following sections.

Building a One-to-Many Report with the Report Wizard

Building a one-to-many report with the Report Wizard is quite easy; just follow these steps:


  • Click Reports in the Objects list and double-click Create Report by Using Wizard.

  • Use the Tables/Queries drop-down list to select the first table or query whose data will appear on the report.

  • Select the fields you want to include from that table.

  • Select each additional table or query you want to include on the report, selecting the fields you need from each.

  • Click Next. Step 2 of the Report Wizard offers a suggested layout for your data (see Figure 6.16). You can accept Access's suggestion, or you can choose from any of the available layout options. Click Next.

    Figure 6.16. Step 2 of the Report Wizard: selecting a layout.

  • Step 3 of the Report Wizard asks whether you want to add any grouping levels. Grouping levels can be used to visually separate data and to provide subtotals. In the example in Figure 6.17, the report is grouped by city, and after adding CompanyName, will also be grouped by company name. After you select grouping levels, click Next.

    Figure 6.17. Step 3 of the Report Wizard: selecting groupings.

  • Step 4 of the Report Wizard lets you select how you want the records in the report's Detail section to be sorted (see Figure 6.18). This step of the wizard also allows you to specify any summary calculations you want to perform on the data (see Figure 6.19). Click the Summary Options button to specify the summary calculations. Using the button you can even opt to include the percent of total calculations.

    Figure 6.18. Step 4 of the Report Wizard: selecting a sort order.


    Figure 6.19. Adding summary calculations.

  • In step 5 of the Report Wizard, you select the layout and orientation of your report. Layout options include Stepped, Blocked, Outline 1, Outline 2, Align Left 1, and Align Left 2.

  • Step 6 of the Report Wizard lets you select from predefined styles for your report, including Bold, Casual, Compact, Corporate, Formal, and Soft Gray. You can preview each style to see what it looks like.

  • In step 7 of the Report Wizard, you select a title for your report. The title also becomes the name for the report. I like to select an appropriate name and change the title after the wizard is finished. The final step also allows you to determine whether you want to immediately preview the report or to see the report's design first.


  • The report created in the previous example is shown in Figure 6.20. Notice that the report is sorted and grouped by City and CompanyName. The report's data is in order by OrderDate and ProductName within a CompanyName grouping.

    Figure 6.20. 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 tablesfiguring out how to build the complex queries needed for the report or formwas one of the major enhancements in Access 95. 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, as a developer, 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 Query

    Another 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 6.21).

    Figure 6.21. 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, creating the report is the same process as the one used for the previous report.

    Building a One-to-Many Report with the Subreport Wizard

    You can also create a one-to-many report by building the parent report and then adding a SubForm/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 (as shown in Figure 6.20). If you want to use the SubForm/SubReport Wizard, you must make sure that you select the Control Wizards tool before you add the SubForm/SubReport control to the main report. Here is the process:

    NOTE

    If you did not do a complete install of Microsoft Access, the SubReport wizard might not be available to you. To run these examples, you must first install the SubReport wizard.


  • Click to select the SubForm/SubReport control tool.

  • Click and drag to place the SubForm/SubReport control on the main report. You will usually place the SubForm/SubReport control in the report's Detail section. When you have placed the SubForm/SubReport control on the report, the SubReport Wizard is invoked.

  • Indicate whether you want the subreport to be based on an existing report or form or you want to build a new subreport based on a query or table. Click Next.

  • If you select Table or Query, you have to select the table or query on which the subreport will be based. You can then select the fields you want to include on the subreport. You can even select fields from more than one table or query. When you're finished, click Next.

  • The next step of the SubReport Wizard suggests a relationship between the main report and the subreport (see Figure 6.22). You can accept the selected relationship, or you can define your own. When you're finished, click Next.

    Figure 6.22. The SubForm/SubReport Wizard: identifying the relationship.

  • The final step of the SubReport Wizard asks you to name the subreport. To follow standards, the name should begin with the prefix

    rsub . Click Finish when you're finished.


  • As you can see in Figure 6.23, the one-to-many relationship between two tables is clearly highlighted by this type of report. In the example, each customer is listed. All the detail records reflecting the orders for each customer are listed immediately following each customer's data.

    Figure 6.23. A completed one-to-many report created with the SubForm/SubReport Wizard.


    Working with Subreports


    When a subreport has been added to a report, it's important to understand what properties have been set by the SubReport Wizard so that you can modify the SubReport control, if needed. You should become familiar with a few properties of a subreport:

    • Source Object
      The name of the report or other object that's being displayed within the control.

    • Link Child Fields
      The fields from the child report that link the child report to the master report.

    • Link Master Fields
      The fields from the master report that link the master report to the child report.

    • Can Grow
      Determines whether the control can expand vertically to accommodate data in the subreport.

    • Can Shrink
      Determines whether the control can shrink to eliminate blank lines when no data is found in the subreport.


    Not only should you know how to work with the properties of a 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 within the list of reports in the Database window. To do this, click the report you want to modify; then click Design. You can also modify a subreport by selecting its objects directly within the parent report.

    TIP

    Access 2002 and Access 2003 make it easier to work with subforms and subreports in Design view. Scrolling has been improved so that it's easier to design subforms and subreports. In addition, you can now open subreports in their own separate Design view window by right-clicking the subreport and selecting Subreport in New Window. Alternately, instead of right-clicking the subreport, you can select the subreport and then click View, Subreport in New Window from the menu bar.


    / 544