Share via


Adding a Subreport to the Original Report

To begin, you add a subreport to the original report.

To add a subreport

  1. Open the project you created in the previous tutorial, Tutorial: Reading and Setting Discrete Parameters.

  2. From Solution Explorer, double-click the CustomersByCity report to open it.

  3. Right-click the Details gray bar and select Insert Section Below.

  4. Right-click within the new Details b section that you have created, point to Insert, and then click Subreport.

A gray square appears around the mouse cursor.
  1. Drag the gray rectangle into the new Details b section, and then click to release.

  2. In the Insert Subreport dialog box, on the Subreport tab, select Create a subreport with the Report Wizard.

> [!NOTE]
> <P>The Insert Subreport dialog box includes other options that allow you to choose an existing report and on-demand subreports. For more information on these features, see <A href="ms227973(v=vs.90).md">Subreport Tab (Insert Subreport Dialog Box)</A>.</P>
  1. In the New report name field, type "CustomerOrders."

  2. Click Report Wizard...

  3. In the Available Data Sources panel of the Standard Report Creation Wizard window, expand the Create New Connection folder.

  4. From the subfolder that opens, expand the ODBC (RDO) folder.

  5. In the ODBC (RDO) window, select the correct ODBC DSN entry for your version of Crystal Reports as explained in ODBC DSN Entry for Xtreme Sample Database, and then click Finish.

The ODBC (RDO) folder expands and shows the Xtreme Sample Database.
  1. Select the Orders table and click the > symbol to move the Orders table into the Select Tables panel, and then click Next.

  2. From the Available Fields panel, select Order ID, Order Date, Ship Date, and Ship Via.

  3. Click the > symbol to move these fields into the Fields to Display panel, and then click Finish.

  4. In the Insert Subreport dialog box, select the Link tab.

  5. In the panel Container Report field(s) to link to, in the list Available fields, expand the Customers table, select Customer ID, and then click the > symbol.

  6. In the Customers.Customer ID field link panel that appears, leave the default selections unchanged.

These parameter and data selections auto-generate a relationship between the main report and the subreport.
  1. Click OK.
The new subreport, CustomerOrders, is displayed within the Details b section of the Main report.


> [!NOTE]
> <P>When you add a subreport to the Details section, the subreport displays for every row, which adds a performance cost to your report. If you do not need subreport information with that level of granularity, place the subreport in a Group section rather than a Details section.</P>

To verify the settings in the subreport

  1. In the report Details section, double-click on the CustomerOrders subreport to view it.

    At the bottom of the designer view, navigation buttons appear for both the Main Report and the CustomerOrders subreport.

  2. If the Field Explorer is not visible, on the Crystal Reports toolbar, click Toggle Field View.

    Note

    Another way to display the Field Explorer is to go to the Crystal Reports menu, and then click Field Explorer.

  3. In the Field Explorer, expand Parameter Fields.

  4. Verify that the parameter field Pm-Customers.Customer ID was auto-generated when the subreport was linked.

  5. On the Crystal Reports toolbar, click Select Expert.

  6. In the Select Expert dialog box, verify that the criteria Orders.Customer ID is equal to {Pm-Customers.Customer ID} is set, and then click OK.

  7. From the File menu, select Save All.

You have successfully added a CustomerOrders subreport to the CustomersByCity report.

To add an OrderDateRange parameter to the subreport

  1. In the Field Explorer , right-click Parameter Fields and select New.

  2. In the Create Parameter Field dialog box:

1.  Set the Name to "OrderDateRange."
2.  Set the Prompting text to "Specify a Date Range of Orders to display."
3.  Set the Value type to " Date."
4.  Set the Options to one selection only, " Range value(s)."
  1. Click OK.

  2. On the Crystal Reports toolbar, click Select Expert.

  3. Click the New tab.

  4. In the Choose Field dialog box, expand the Orders table, select Order Date, and then click OK.

  5. On the new Orders.OrderDate tab, from the drop down criteria list, select formula and type the following formula: {Orders.Order Date} in {?OrderDateRange}

  6. Click OK.

  7. From the File menu, select Save All.

You have successfully added an OrderDateRange parameter to the subreport and linked it to the Orders.OrderDate column. In the next section, you add code to address the OrderDateRange parameter within the subreport.