Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

9.09 Tutorial 9-2 Linking the Subreport with a Data Field

Tutorial 9-2. Linking the Subreport with a Data Field

Let’s start working with subreports by creating a subreport that links to the main report using a data field. We are going to take the Customer Sales Report we created in the previous tutorial and list the customer credits on it. We’ll link the two reports together using the Customer Credit ID field which is found in both tables.

  1. Open the report you just created, ‘Customer Sales.rpt’ and save it as Customer Credits.rpt.
  2. The group footer was created using two sections. The lower edge of the gray box is in section A and section B is empty. We want to fit the subreport within the gray box, so we’re going to put it in section A.
  3. Go into design mode and look at the gray box surrounding the group sections and details section. Right now, it stops in section Group Footer #1a. Click on it and drag it so that it extends into the next section below, Group Footer #1b. This frees up space in Group Footer #1a so we can insert the subreport.
  4. Make Group Footer #1a larger (about double its current size) so you can place the subreport object into it.
  5. Create a new subreport by selecting the menu options Insert > Subreport. This opens the Insert Subreport dialog box.
  6. The default option is to create a new report using the Report Wizard. That is what we want. Enter a report name of Customer Credits and click the Report Wizard button.
  7. When the report wizard opens, select the Xtreme.mdb database.
  8. Select the Credit table and put it in the Selected Tables list on the right. Click the Next button.
  9. For the fields to display, select Credit Authorization Number and Amount.
  10. Click the Finish button to save your report settings and return to the Insert Subreport dialog box.
  11. Click on the Link tab so that we can set the linking field.
  12. The Customer table and Credit table are linked together by the field Customer Credit ID. Find it in the Available Fields list on the left and double-click it to put it in the list Fields To Link To.

At the bottom, you will see that Crystal Reports has created a link between the reports. On the left side is a parameter that will be used internally by Crystal Reports to pass the field data to the subreport. On the right side is the Customer Credit ID field in the Credit table. Since the tables in both the master report and subreport both have the same field name, Crystal Reports was able to accurately pick the linking field. However, many times this won’t be the case and you will have to click the dropdown box and choose the linking field manually. For this example, everything is fine as it is. The dialog box should look like the following figure.


  1. Click the OK button to save your changes and close the dialog box.

When you return to design mode of the main report, an outline of the subreport object is shown as a rectangle. Use the mouse to position the subreport within Group Footer #1a. Click the mouse button to release it.

When you preview the report, you should see the credits for each customer listed below the sales detail. Since we linked the subreport on the field Customer Credit ID, each customer has only their credits listed. Let’s clean up the report just a little before we are finished.

  1. Go back into design mode and resize the subreport object. Shorten the width of the subreport by dragging the right side closer to the left. Then move the subreport object to the right so that it is centered on the report.
  2. Double-click on the subreport object. This opens the subreport in design mode on its own tab.
  3. Click on the Report Date object in the Report Header section and delete it. The subreport doesn’t need to show the report date.
  4. Now that we deleted the report data, there is too much empty space in the report header. Select the column headers and move them to the top of the report header section. Then resize the report header section to make it smaller. Also, resize the Report Footer to make it a lot smaller (there isn’t anything being displayed in it).
  5. Save the report (make sure you renamed it in Step 1) so that you don’t lose your changes. Preview the report and it should look similar to the following figure.