Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

8.05 Adding Multiple Sections

Adding Multiple Sections

Throughout this book, when different parts of a report were discussed, they were referred to by their section name. For example, when adding an object to be displayed in the header of a group, the portion of the report would be called the Group Header section. But what you weren’t told is that each section is actually contained in an Area. Areas let you build more complex reports. Simple reports don’t require working with Areas so they weren’t mentioned. But in this section, you’ll see that Areas are actually a container for one or more sections and you’ll see how to use them to create advanced report formatting.

By default, when you create a new report, each area is composed of a single section. There is an area for the Report Header, Page Header, Details section, etc. Every section is contained inside a single area. This initially gives you a one-to-one relationship between areas and sections.

Crystal Reports lets you create dynamic reports by adding multiple sections within an area and format each section independently of the other. This changes the relationship between areas and sections to a one-to-many relationship. One area can have multiple sections within it. You have the option of displaying all the sections or you can use conditional formatting to set which sections are visible and which ones are suppressed.

An area can have more sections added to it, but the sections must be of the same type. For example, the Details area can have two Detail sections in it, but it can’t have a Group Footer section in it.

An example of multiple sections is shown in Figure 8-8.



Figure 8-8. Multiple detail sections.

In this example, there are two sections between the group header and footer: Details a and Details b. Each section is part of the Details area. The benefit of having two sections within the same area is that it gives you a lot of flexibility for formatting the report. Creative use of multiple sections solves many reporting problems.

Before seeing how to work with multiple sections, you first have to understand the rules. The first rule is that multiple sections are printed consecutively. The first section (labeled with the ‘a’) prints first. The ‘b’ section is printed second, and so on. The second rule is that you can change the formatting of any section and it doesn’t effect the formatting of the other sections. A section can be suppressed or have its background color changed and this has no effect on the other sections within that area.

Multiple sections can be inserted, deleted and merged with other sections. When you right-click on a section header, you get the menu shown in Figure 8-9.



Figure 8-9. Menu for managing sections.

When selecting Insert Section Below, it inserts a new section below the section that was clicked on. Select Merge Section Below to combine the current section with the one below it. Crystal Reports merges the two by taking all the objects in the lowest section and copying them to the section above it. All the new objects go underneath the existing objects. Select Delete Section to delete a section from the report.

If a section has too much white space underneath the report objects, make the space tighter by placing your cursor at the top of the section below it and dragging it higher. An easier, and more accurate, way of doing this is to select the Fit Section menu option. Crystal Reports adjusts the section height to fit the exact space needed for the report objects. No extra space is allocated.

Selecting Move Section brings up the Section Expert again. This dialog box displays all the report sections on the left-hand side. Now that you have multiple sections, you can use the arrow keys shown at the top to move the sections up or down. This changes the order that they are printed in.



Figure 8-10. The Section Expert with multiple sections.

When looking at the menu options along the top of this dialog box, you see that it also has the options to Insert, Delete and Merge sections. If you are working in the designer, you can also go to this dialog box by right-clicking on a section header and selecting Format Section.

The key to making multiple sections work is to tie their properties with conditional formatting formulas. As discussed in Chapter 5, conditional formatting is used to turn formatting options on and off using built-in functions with other data in the report. The best way to understand this is to see examples. The following tutorials present common uses of conditional formatting with multiple sections that you can use in your own reports.