Adding a Subreport
A subreport is added to the main report in the same way that the other report objects are added: using the Insert menu item. Select the menu options Crystal Reports > Insert > Subreport. This gives you the outline of a subreport object attached to the mouse cursor and you move the cursor around to position it in the proper place on the report. Click the mouse to drop the subreport onto the report.
Subreports can only be one level deep. A subreport object can only be added to a main report and it can’t be added to another subreport. If you right-click on a subreport and select Insert, the Subreport option will be disabled.
After placing the subreport object on the report, the Insert Subreport dialog box is opened. This dialog box, shown in Figure 12-3, gives you three ways of creating a subreport.
Figure 12-3. The Insert Subreport dialog box.
The first way is to select an existing report that is in the current project. Click on the dropdown box to see all the reports in your project. Select the one you want. The second way to create a subreport is to import one from outside the project file. The Browse button lets you find the report on your local computer or on the network. The third way is to create a report from scratch. When selecting this option, you also have to click on the Create Report button to open the Report Expert dialog box. If you don’t click this button, the OK button will stay disabled until you do so. The Report Wizard button opens the Report Expert for a standard report. Once you are finished building your report template, click Finish and you are brought back to the Insert Subreport dialog box. The OK button is now enabled, but don’t click on it until you decide how to link the subreport to the main report.
When importing an existing report as a subreport, whether already in the project or external to the project, the subreport is a copy of the original report. When you make changes to the subreport, the original report is not modified. The subreport is saved within the same .rpt file as the main report.
After setting the report information on the main tab, go to the Links tab (shown in Figure 12-4) to set whether the report is linked or unlinked.
Figure 12-4. The Links tab of the Insert Subreport dialog box.
This dialog box is where you set the properties that determine how the subreport is linked to the main report. The Links tab has a list on the left side that shows the available report fields, formulas and data fields. The list on the right shows the fields from the main report that are selected to link to the subreport. At the bottom is a frame that shows the details of how the field(s) will be linked to the subreport. These linking options and how to set the properties for each are listed next.