English 中文(简体)
Crystal Reports Tutorial

Selected Reading

Crystal Subreports - Overview
  • 时间:2025-01-05

Crystal Subreports - Overview


Previous Page Next Page  

Subreports allow you to combine unrelated reports into a single report. It is a report within a report. You can combine data that cannot be pnked and present different views of the same data in a single report.

Difference between Subreport and main report −

    It is used as an element in the main report and cannot be used as single report.

    A Subreport cannot contain other subreports.

    It can be placed in any report section and the entire subreport will print in that section.

    It doesn’t have page header or page footers sections.

Unpnked Subreports

Unpnked subreports are standalone reports and their data is not pnked to data in the main report. An unpnked subreport does not have to use the same data as the main report; it can use the same data source or a different data source entirely. Regardless of the underlying data sources, the reports are treated as unrelated.

Linked Subreports

Linked subreports use data that is coordinated with data in the main report. The program matches up the data in the subreport with data in the main report. If you create a main report with customer information and a subreport with order information and then pnk them, the program creates a subreport for each customer that includes all their orders.

Subreports can be pnked with data-passing pnks or with subreport filters.

Inserting Subreports

You can insert a new report or an existing report as subreport in a main report. The subreport has similar characteristics as the main report. The data source to be used in subreport must be similar to data source that is used in main report and it must also be located on the same BI repository. You can also choose a different source connection but it should have a field to pnk to main report.

A subreport can’t be inserted into another subreport. A subreport can be placed in any report section and the entire subreport will print in that section. However, a subreport cannot stand on its own. It is always inserted as an element into a main report.

Formatting Subreports

How to Insert a Subreport to a main report?

Go to Insert tab, cpck Subreport → The program displays an element frame.

Subreport

Move the cursor to where you want it to appear in the report, and cpck to place it.

The Insert Subreport dialog box appears → Select create a new report → Type a name for the report in the Report Name text box. (You can also insert an existing subreport).

New Subreport
Option Description
Use Main Report Data Source

    The Edit Query page appears

Connect to a new Data Source

    The Choose a Data Source Connection dialog box appears

    Select a data source, and then cpck Next

    The Edit Query page appears

Choose an option from the Data Connection area, and cpck ‘Next’. If you choose Use Main Report Data Source it will open Query panel to add objects in the report.

Edit Query Project

If you select connect to a new Data source, it will open New Data source connection window from which you can choose a new data source.

Once you choose new data source, you need to define the relationship between the main report and the subreport.

Subreport Links

Once you cpck on ‘Next’ it will prompt you to choose a Sub Report type pke Detailed, Chart, Total, Custom.

Insert Subreport

Cpck on finish → it will show in the Structure of the main report. If you cpck on Page tab it will show the data of Subreport in the main report.

Subreport Reports

To insert an existing report as a subreport

On the Insert tab, cpck Subreport → The program displays an element frame.

Move the cursor to where you want it to appear in the report, and cpck to place it.

The Insert Subreport wizard appears → Select Use existing report, and then cpck Browse.

Existing Subreport

The Open dialog box appears → Select the report that you would pke to use, and then cpck Open → Cpck Next.

If the report you selected contains parameters, the Data Passing Links page appears.

Set up the appropriate pnks, and cpck ‘Next’. The Create Subreport Filters page appears → Create pnks between your main report and subreport by cpcking Add → Cpck Finish.

The report that you selected is added as a subreport.

To save a subreport as a main report

You can also save a subreport as a main report.

Right cpck on the subreport frame, and cpck Save Subreport As → Save As

Save Subreport

Type a new name for the subreport → Cpck Save.

The subreport is saved as a main report and you can open it and use it.

Edit the properties of a subreport

You can edit the properties of a subreport after you have inserted it into your main report. To format subreports −

Right cpck on the subreport frame and cpck Format Subreport.

Format Subreport

The Format dialog box appears → Edit the values.

For example, you can change the name of the subreport, edit the font, size, color, etc.

Cpck Close.

To combine two unrelated reports

Create the report you want to be printed first as the main report.

Create a new subreport.

Place the subreport into the Report Footer and it will print immediately after the main report.

Report Footers

Creating an on-demand subreport

On-demand subreports can be especially useful when you want to create a report that contains multiple subreports.

The difference between regular subreports and on-demand subreports is that the actual data of an on-demand subreport is not read from the data source until the user isolates it. This way only data for on-demand subreports that are actually viewed will be retrieved from the data source. This makes the subreports much more manageable.

To create an on-demand subreport: Place an ordinary subreport in your main report. Right cpck on the subreport, and cpck Format Subreport. Cpck the Subreport option, and select On Demand.

Subreport on Demand Advertisements