Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

3.31 Tutorial 3-9. Group Headers that Repeat

Tutorial 3-9. Group Headers that Repeat

When grouping data, it is common to repeat the group header section at the top of each group. This can include printing the group name and column headers. While this is very helpful, there are times when this makes things tricky because you don’t always want the group header fields printed every time. For example, consider a report that has a group header which displays the group name at the top of the page and right below it are the column headers. The report has a requirement where the group name should be printed at the beginning of each group but not on successive pages. However, the column headers should always be printed on every page.

This requirement creates a problem because part of the header (the group name) should only be printed once per group and the other part (the column headers) should be printed at the top of each page. Both of them belong in a Group Header section, but they have different behaviors. The solution is to break the header into two sections and format each section differently.

Crystal Reports gives you the ability to find out when a group is repeated on a page. You can use the function InRepeatedGroupHeader to disable certain fields so that they only get printed once for each group.

Function Description
InRepeatedGroupHeader Call this function within the group header section. It returns false the first time a group header is printed. It returns true for the second and later time that the group header is printed. Note: For the group header to be printed at the top of each page, you have to have the option Repeat Group Header on Each Page enabled.
  1. Open an existing report that has uses a group header with multiple fields in it. You can use the report in Tutorial 3-6 if you wish, but you’ll first need to move the column headings from the Report Header into the Group Header.
  2. To make the group header repeat on each page, select Report > Group Expert. This opens the Group Expert dialog box.
  3. Click on the group field in the list on the right and click the Options button. This opens the Change Group Options dialog box.
  4. Select the Options tab.
  5. Click the checkbox Repeat Group Header on Each Page. This forces the repeated header to appear at the top of each successive page.
  6. Since you only want part of the header to appear at the top of each page, you need to add a second group header section. Right-click on the Group Header and on the pop-up menu select Insert Section Below. This creates a second group header section directly below the existing one.
  7. Move the column headers into the new section. You can do this by selecting them and dragging them into the new section, or by cutting and pasting them there. Leave the other text objects in the top group header section. At this point the group header looks the same, but the fields are split into two different sections.
  8. Right-click on the group header and select Section Expert. This opens the Section Expert dialog box.
  9. Click on the group header for Section A and click on the Formula button for the Suppress property.
  10. Enter the following formula:

InRepeatedGroupHeader

This function returns True when the group header is about to be printed on a second page. By returning True, it turns on the Suppress property so that the group name doesn’t get printed after the first page. Since this formula is only used in Section A, it doesn’t affect Section B. The column headers in Section B will be printed on every page.

  1. Click the Ok buttons until all the dialog boxes close and you return to the report designer.
  2. Save and preview the report. Notice that the group name only gets printed once per group and the column header gets printed at the top of each page.
  3. You can also use the InRepeatedGroupHeader function to add a “Cont.” string to subsequent group headings. This tells the user that the group started on a previous page. Set the Suppress property of the text object to use the following formula:

Not InRepeatedGroupHeader;

Since the Boolean Not operator prefixes the function, this causes the “Cont.” to be suppressed the first time the group header is printed and to be displayed on the successive pages.