Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

12.11 Editing the Subreport

Editing the Subreport

Once the subreport object has been added to the main report, you will probably need to edit it. Depending upon the types of changes you want to make to the subreport, there are different ways of editing it.

To edit the content of the subreport, from the main report either double-click on the subreport object or right-click on it and select Edit Subreport. This opens the subreport in the same design tab as the main report. The subreport is now treated the same as any other report. You can add new report objects, modify existing ones, or delete report objects.

When editing a subreport, the report designer changes so that it displays tabs at the bottom of the designer. Each tab lists the name of the main report and all open subreports. This lets you move back and forth between the main report and its subreports. This is shown in Figure 12-6.



Figure 12-6. The tabs that list the main report and open subreports.

If you have a main report that uses many subreports, you may find that you can’t open them all and see their tabs listed at the bottom of the designer. As of now, Crystal Reports doesn’t have a way to scroll to the other tabs. Thus, you will not be able to have all subreports open at one time. To make room for more tabs, go to a subreport that doesn’t need to stay open and right-click on it to open the menu. Select Close Subreport. This closes the subreport and removes the associated tab from the designer. Now there is room for a new subreport to be opened.

You can also modify other aspects of the subreport. When viewing the main report in design mode, right-click on the subreport object and there are two menu options called Format and Change Subreport Links. The Format menu item opens the standard format dialog box where you set properties such as Suppress, Keep Object Together, etc. The formatting options on the Border, Subreport and Font tabs control how on-demand subreports are displayed on the main report. This is discussed in the next section. The Change Subreport Links menu item opens the Subreport Links dialog box. This lets you change the fields that are used to link the main report to the subreport.

One of the formatting oddities of subreports is there is no easy way to suppress a subreport with no data. Setting the formatting option Suppress Blank Section doesn’t have any effect because the subreport is an object on the main report and the section isn’t considered to be blank. Since subreports typically have column headings just like other reports, a subreport with no data will still print their column headings.

Getting around this problem requires making quite a few changes to trick the main report into not printing the subreport. The general idea is to make a copy of the subreport and put it in the next section on the main report. The first subreport has to set a shared Boolean variable that tells whether there are any records in the report. Then this subreport must be resized so that it doesn’t take up any room on the main report. The next step is to use that shared variable on the main report so that the second subreport is conditionally suppressed when the variable is True.