Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

12.04 Using Unlinked Subreports

Using Unlinked Subreports

An unlinked subreport is used when you want to combine two or more reports onto one report and these reports don’t have any common data to create a relationship between them. The unlinked subreport is completely independent of the main report and the main report’s data doesn’t affect the subreport.

Figure 12-2 shows an example of an unlinked subreport. It is a customer sales report that shows the prior year sales amount for each customer.



Figure 12-2. Unlinked subreport being used in the report header.

The report is grouped by country and within each group it shows the customers from that country and what their sales were last year. At the top of the report it shows a summary of the prior year sales for each country. This lets you analyze how each country compares to the other before looking at detail records within each customer. Since there isn’t a field that can be linked between the summary report and the customer detail report, these two reports are unlinked. This is implemented by adding the summary report as a subreport in the main report’s header section.

Let’s look at an example of an unlinked subreport that at first may appear to be a linked report. This example is a form letter that has a variable number of standard attachments printed at the end of it. This could be a legal document where each client needs to have signature pages attached to the end of it.

Within the Report Footer area, there are multiple sections. Within each section is a subreport that represents a standard attachment. The conditional formatting suppresses the section if a field in the main report doesn’t meet a certain value. In this case, the person receiving the form letter would have Boolean fields that are set to True for each attachment that should be included. If the proper field isn’t set to True, the section is suppressed and the attachment isn’t printed. Although this may appear to be a linked subreport because data in the main report determines whether to print the subreport, it isn’t. It is an unlinked subreport because there is no data that is being passed to the subreport. The Boolean field in the main report determines which sections get suppressed or printed. But this is all done at the main report level and not at the subreport level. The Boolean field never gets passed to the subreport and its value doesn’t affect the content of what is printed.

Using Formula Fields without Linking

Formula fields can also be used by a subreport without linking them. This is used when you want to pass data to a subreport without filtering the data. For example, the main report can pass a string to the subreport so that the string gets printed in the subreport’s header.

Passing Data Via Shared Variables

Shared variables let you share data between a main report and its subreports. This lets you perform calculations, track subtotals and create strings in one report and pass this data to the other report.