Export (0) Print
Expand All

Adding a Subreport to the Original Report

Visual Studio 2005

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

To add a subreport

  1. Open the project you created in the previous 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.

  5. Drag the gray rectangle into the new Details b section, and then click to release.
  6. In the Insert Subreport dialog box, on the Subreport tab, select Create a subreport with the Report Wizard.
    Note   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 Insert Subreport Dialog Box.
  7. In the New report name field, type "CustomerOrders."
  8. Click Report Wizard...
  9. In the Available Data Sources panel of the Standard Report Creation Wizard window, expand the Create New Connection folder.
    Note   In Visual Studio .NET 2002 or 2003 where Crystal Reports has not been upgraded to Crystal Reports Developer, the Create New Connection folder does not exist; the contents are shown at the top level.
  10. From the subfolder that opens, expand the ODBC (RDO) folder.
  11. 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.

  12. Select the Orders table and click the > symbol to move the Orders table into the Select Tables panel, and then click Next.
  13. From the Available Fields panel, select Order ID, Order Date, Ship Date, and Ship Via.
  14. Click the > symbol to move these fields into the Fields to Display panel, and then click Finish.
  15. In the Insert Subreport dialog box, select the Link tab.
  16. 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.
  17. 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.

  18. Click OK.

    The new subreport, CustomerOrders, is displayed within the Details b section of the Main report.

    Note   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.

You are now ready to verify the settings in the subreport.

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. In the next section, you add an OrderDateRange parameter to the subreport.

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:
    • Set the Name to "OrderDateRange."
    • Set the Prompting text to "Specify a Date Range of Orders to display."
    • Set the Value type to "Date."
    • Set the Options to one selection only, "Range value(s)."
  3. Click OK.
  4. On the Crystal Reports toolbar, click Select Expert.
  5. Click the New tab.
  6. In the Choose Field dialog box, expand the Orders table, select Order Date, and then click OK.
  7. On the new Orders.OrderDate tab, from the drop down criteria list, select formula:
  8. Type the following formula:

    {Orders.Order Date} in {?OrderDateRange}

  9. Click OK.
  10. 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.

Continue to Adding the Subreport Parameter Code.

See Also

Tutorials: Reading and Setting Range Parameters for a Subreport | Tutorials and Sample Code | Tutorials' Sample Code Directory

Show:
© 2014 Microsoft