Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

9.08 Linked Subreports

Linked Subreports

Linked subreports require the main report to pass information to the subreport so that the subreport can filter its data. There are two ways that the reports can be linked to each other. You can use a field from the data source or use a formula for custom linking. Let’s look at the details of the different linking methods and practice with some tutorials.

Linking with a Data Field

Linking subreports with a data field lets you filter the data in the subreport based upon a data field that comes from the main report. This is useful when you are printing data derived from tables that have a parent-child relationship (as discussed earlier).

An example of linking with a data field is shown in Figure 9-6. This report shows the sales detail for each customer. Below the detail records is a list of all the credits that have been issued to the customer. Since there are two listings of detail records, the second list must be printed as a subreport. In this example, the subreport is linked via the Customer ID and it was added to the main report’s Group Footer section.



Figure 9-6. Linked subreport in the Details section.

There are two requirements for linking with a data field. The first is that the two fields must be of the same data type. The second requirement is that if this is a PC database, then both fields must have an index already set up in the database.

To create a linked subreport, go to the Link tab of the Insert Subreport dialog box. Select the data field from the Available Fields list on the left and add it to the Fields To Link To list on the right. Once the data field is added, the linking frame at the bottom appears and shows you the parameter field name and the field in the subreport’s data field to link to. The parameter name is automatically filled in for you.

The checkbox on the right tells the subreport that the main report’s data field is being linked to a field in the subreport. Leave this checked. Below the checkbox is a dropdown box listing the fields in the subreport. Select the one that is used to filter the data in the subreport. It must be of the same data type as the field from the main report. Click the OK button to save your changes and preview the subreport.