Crystal Reports  

Inserting Subreports

A subreport is a report within a report. With subreports, unrelated reports can be combined into a single report. You can coordinate data that could not otherwise be linked, or you can present different views of the same data in a single report.

If your report has a section that handles a large number of records, you can put that section into an on-demand subreport. An on-demand subreport appears as a hyperlink in the primary report. When you open the primary report, no data is retrieved for the on-demand subreport until you drill down on the hyperlink.

Tip   Whenever possible, coordinate your report data by linking database tables with the Visual Linking Expert, rather than by linking regular subreports — that is, subreports that aren't on-demand subreports — to the main report. Since each subreport is run as a separate report, linked tables often have a performance advantage.

To insert a subreport

  1. Right-click in the Crystal Reports ActiveX Designer, point to Insert, and click Subreport.
  2. Drag the subreport object onto the report.
  3. Choose a report in your project, another existing report, or create a new report for the subreport.
  4. Choose On-demand Subreport to have the ability to retrieve the data on the subreport when needed. Otherwise, all subreport data will appear with the report.
    Note   Using on-demand subreports will increase the performance of reports that contains subreports.
  5. Click the Link tab if you need to link a subreport to the data in the main report.
  6. Select the field you want used as a link field in the primary (containing) report from the Available Fields list.
  7. Use the field link section (which will appear only if you have selected a link field) to set up the link for each link field:
    • select the field you want linked to the primary report from the Subreport parameter field to use.
    • select the Select data in subreport based on field check box on and select a field from the adjacent drop-down list to organize the subreport data based on a specific field (this is the quick equivalent of using the Select Expert). If nothing is specified here, the subreport will adopt the organization of the primary report.
  8. Click OK.

When you run the report, the program will coordinate the data in the primary report with the data in the subreport.

Note   The field type of the Containing Report field determines which subreport fields are visible. Because the Crystal Reports ActiveX Designer reads dates as either strings, dates, or date/time fields, you must make sure your subreport parameter field type matches the field type set up in Report Options in the main report for the field you want linked.

See Also

Unlinked vs. Linked Subreports