Using Multiple Report Sections

Including multiple sections within each section area of your report provides for an extremely flexible presentation of your report data. Chances are good that you will not need to create more than one occurrence of any of the existing report sections for basic reporting needs. However, Crystal Reports allows you to define multiple report sections within any given section area and to identify section-specific properties for challenging formatting requirements within more complex reports. Certain reporting tasks are performed most efficiently by creating multiple sections within an area.

graphics/bookpencil_icon.gif

A Section Area is the space in which one or more of the same Report Section types are defined. For example, it is possible to define two or more Page Header sections in a report to satisfy complex formatting requirements (covered later in this hour), and the area in which these Report Header sections are displayed is referred to as the Section Area.


For example, multiple report sections would be very useful if you want to create a form letter for your customers and you need to display only one of two possible return addresses on the letter an American address for customers based in the United States and a Canadian address for the remainder of your North American customers. To accomplish this, you will need to insert two report header sections in to your report and use Conditional Formatting to dynamically apply the appropriate return address based on where the customer is located.

graphics/bookpencil_icon.gif

Conditional Highlighting allows you to define a formula that causes a specific action (formatting in this case) to occur if the formula's results are true. This is also referred to as a format formula.


In order to demonstrate how to implement and use multiple report sections, we first need to review the basic operations of resizing, inserting, removing, and merging report sections.

Resizing Report Sections

Report sections might require resizing to accommodate for various sized report objects, such as large database fields, lengthy text objects, or corporate logo images, but they cannot exceed the size of the report page itself. From the Design tab of the report environment, you can drag the bottom boundary of the various sections up and down with the mouse to resize each section. Using the mouse, float the pointer over the horizontal boundary lines of the different sections. When the mouse pointer changes into a double-headed arrow icon, click and hold the left mouse button while dragging the boundary line to the desired position.

Inserting New Report Sections

To display only one of two possible return addresses on a form letter (based on the location of the customer), we need to insert a second page header on to the report. To begin this exercise, either open report 09Report04, as shown in Figure 9.7, or construct the report using the Customer table from the Xtreme Sample Database. By following a few easy steps, you can quickly create the form letter report:

  1. Using the Xtreme Sample database, choose not to add any database fields to the report.

  2. Create a Group based on the Customer Name field, but do not display the Customer Name field in the Details section. The Group field should automatically appear in the Group Header section.

  3. Select the New Page After property for the Group Footer #1 section.

  4. Suppress the Report Header section.

  5. Insert text objects in the appropriate report sections, as shown in Figure 9.7.

Figure 9.7. An example of a simple form letter report.

graphics/09fig07.jpg

graphics/bookpencil_icon.gif

Notice that in this sample form letter report, each report object displayed on the report is just a text object inserted in to the appropriate section. You do not yet need to include any database fields in the report.


  1. To insert a new Page Header section, locate the existing Page Header section, right-click on the section name (on the left of the design environment), and select Insert Section Below from the pop-up menu.

You added a new section entitled "Page Header b" and renamed the original section to "Page Header a" so that you now have two Report Header sections within your report. The application follows this naming convention whenever you choose to add multiple report sections within any section area, appending each section name with a, b, c, and so on.

  1. After you have inserted a new Page Header section (labeled "Page Header b"), insert a text object to display a Canadian return address to be used for the non-USA recipients of the form letter, as shown in Figure 9.8.

    Figure 9.8. A form letter report with two Page Header sections.

    graphics/09fig08.jpg

Now that we have the two different return addresses and report sections created, we need to identify the necessary logic within the report to implement the appropriate Page Header section based on each customer's location whether they are based in the United States or Canada. We only need to evaluate each customer's mailing address the Country field from the Customer table, to be exact. We're only concerned with North American customers, and if this field is equal to USA, we will use Page Header a to display the return address. If it is equal to Canada, we will use Page Header b.

  1. To isolate our report for only North American customers, choose the Select Expert option from the Report menu. From the list of available fields, select the Country field from the Customer table listing and click OK to continue.

  2. You should now see the Select Expert dialog. From the drop-down list on the left, select Is One Of and include Canada and USA in the list box on the right as shown in Figure 9.9.

    Figure 9.9. Use the Select Expert dialog to quickly filter a report to include only the data you want to retrieve.

    graphics/09fig09.jpg

  3. To add additional personalization to the form letter, use the Field Explorer to insert the Customer Name field into the Text Object located in the Group Header #1 that reads "Dear Customer," so that it will appear as "Dear { Customer Name} ," in the Design tab of your report. To do this, you'll need to modify the text portion of this combined object to read "Dear" that's the word Dear followed by a space, and then followed by the database field object. The result of this action can be seen later in the exercise in Figure 9.10.

    Figure 9.10. The report section will be suppressed only if the conditional statement defined in the Format Formula Editor is true.

    graphics/09fig10.jpg

Finally, we need to apply the logic to display the appropriate return address on the form letter. To do this, we will apply a conditional formatting statement (format formula) to each of the two Page Header sections.

  1. Using the Section Expert for Page Header a, click on the x-2 button (with the pencil symbol) located directly to the right of the Suppress (No Drill-Down) option on the Common tab. After clicking this icon, you should be presented with the Format Formula Editor dialog window. Within the Format Formula dialog, shown in Figure 9.10, you can use the Field, Function, and Operator windows (located in the upper area of the dialog) to insert the necessary format formula within this dialog, or you can just type in the statement in the lower area of the Editor dialog so that it reads {Customer.Country} = "Canada". After you have inserted this statement, click Save and Close to return to the Section Expert.

  2. We now need to implement a very similar formatting condition for the Page Header b section. Following the same procedure used for the first section, use the Section Expert to insert a statement that reads {Customer.Country} = "USA".

graphics/lightbulb_icon.gif

To quickly verify that your formulas are behaving as desired, you can add the customer address database fields on to the form letter as well. This will allow you to check if a customer is in the United States or Canada. We will do this later in the exercise by adding the Country database field to the report.


graphics/bookpencil_icon.gif

If you are not familiar with the Format Formula Editor, also known as the Formula Workshop dialog, do not feel intimidated. Although it might first appear as rather complex, it is a helpful and straightforward environment for creating formulas. In this case, we are using it only to create a conditional formatting formula that, in turn, will populate our report with one of two possible Page Header sections because only one of the two defined conditional formulas will hold true for any given customer. See Hour 10, "Understanding and Implementing Formulas," for additional exercises and details on creating formulas.


It is important to note that formulas are covered in greater detail in Hour 10, and they are only included here for completeness of the exercise on formatting report sections.

  1. After you have inserted the format formulas within the Section Expert dialog, the small icon to the right of the Suppress (No Drill-Down) option should now change to red rather than its earlier blue color, indicating that now a conditional formatting formula is defined to suppress this section.

    graphics/bookpencil_icon.gif

    You do not need to check the Suppress (No Drill-Down) check box in the Section Expert dialog for either report Page Header section. By inserting a format formula, you have effectively applied conditional formatting that will suppress the section if the format formula is found to be true. In this case, one of the two format formulas should also be true because the customers are either located in the United States or Canada. Likewise, almost any property of a section can be conditionally formatted using formulas.


  2. Close the Section Expert dialog by clicking OK. As shown in Figure 9.11, your report should now display only one of the two possible return addresses on the form letter.

    Figure 9.11. A simple form letter report is now dynamically formatted with the appropriate return address based on the customer's location.

    graphics/09fig11.jpg

graphics/lightbulb_icon.gif

To verify that the appropriate return address is being populated on the form letter report for each customer, you can easily add the Country field from the Customer table into the Group Header #1 section, as shown in Figure 9.11.


Deleting Report Sections

In much the same manner as inserting new sections, unused report sections can be quickly removed from reports by right-clicking on the section name and selecting Delete Section from the pop-up menu. Be aware, however, that any report objects positioned within the section will also be deleted from the report. If you want to keep any of the objects within a section that you will be removing, you will need to first relocate the objects into alternative report sections before deleting the current section.

graphics/bookpencil_icon.gif

Crystal Reports requires at least one section to be present for certain section types in every report, such that you will be unable to remove the Report Header and Footer, Page Header and Footer, and Details sections. These report sections are generated by default when creating new reports. Also, if Group objects exist within a report, you will be unable to remove the Group Header and Footer sections unless you first remove the Group object itself from the report. However, if you're unable to actually delete them, you can always suppress these sections for display purposes and achieve much the same effect.


Merging Report Sections

When designing reports, you might periodically want to merge two report sections in order to simplify the layout of a report. To merge the two Page Header sections from our earlier example, right-click on the Page Header a section title and select Merge Section Below from the pop-up menu. The Merge Section Below command is available from the right-click menu of any report section that meets two criteria:

  • There are more than one of the given section type (Page Headers) within the Section Area.

  • The section is not last in a series of sections (Page Headers) consisting of the same section types within a common area.

For example, if three Page Header sections are present on a report (as shown in Figure 9.12), the Merge Section Below command would be accessible from the right-click menus of Page Header a and Page Header b, but not from Page Header c.

Figure 9.12. The Merge Section Below command is available from the right-click menu of certain report sections.

graphics/09fig12.jpg



Sams Teach Yourself Crystal Reports 9 in 24 Hours
Sams Teach Yourself Crystal Reports 9 in 24 Hours
ISBN: B003D7JUVW
EAN: N/A
Year: 2005
Pages: 230

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