Operation Manual

Subreports
What are subreports?
24
Crystal Reports User’s Guide 471
Linked
Linked subreports are just the opposite; their data is coordinated. The program
matches up the records in the subreport with records in the primary report. If
you create a primary report with customer information and a subreport with
order information and link them, the program creates a subreport for each
customer and includes in that subreport all the orders for that customer.
How subreport linking works
When you link a subreport to a primary report, the program creates the link by
using a parameter field.
When a subreport link field is selected, the program creates:
A parameter field in the subreport which is then used to retrieve values
passed to it by the primary report.
A record selection formula for the subreport using the parameter field.
The selection formula limits the subreport to those records in which the
link field is equal to the parameter field value.
When the report is run, the program finds the first primary field record it needs
and passes the value in the link field to the parameter field in the subreport.
The program then creates the subreport with record selection based on the
parameter field value. Here is an example:
You create a report that shows customer data and a subreport that shows
order data and then you link the two reports using the Customer ID field.
When you run the report, the program finds the first customer record it
needs and passes the Customer ID value from that record to the
subreport parameter field.
The program runs the Orders subreport. Since the subreport selection
formula selects only those records in which the Customer ID value is
equal to the parameter field value, and since that parameter field value is
equal to the Customer ID in the first record in the primary report, the
subreport contains only those records that have the same customer ID.
Namely, those records that are orders for the first customer.
When the subreport is finished, the program locates the second record it
needs in the primary report, prints the customer data, and then passes
this customer’s ID number to the parameter field.
The program then runs a subreport including only those order records for
the second customer.
The process continues until the report is finished.