[]
        
(Showing Draft Content)

Master-Detail Report using Subreport

When you want to separate the details from the master report, you can create two separate reports and embed the detail report in the master report using Subreport control. A parameter is passed from the master report to detail report to filter the details.

What You Will Learn

This tutorial guides you through the steps to create a Master-detail report using subreport in Wyn Enterprise Report Designer.

Note: This tutorial uses sample SalesByRegion data set.

After you complete this tutorial, you will have a report that looks similar to the following.


Master-Detail Report using Subreport Example


(Parameter1 = Canada West)

Create Master Report Layout

To create a master report, we will use List data region. The List data region will contain TextBox controls to display the data, and a Subreport control to display detail report. The List data region repeats any report control it contains for every record in the dataset.

  1. Drag and drop List data region List Data Region onto the design area of the report.

  2. Drag and drop two TextBox controls, TextBox1 onto the list and TextBox2 above the list.

  3. Drag and drop the Subreport Subreport Data Region control onto the list. Arrange the controls such that the report now looks like the following.

    Data Regions Arrangement on the Design Area


    Verify that the hierarchy of the controls added in the report is as follows. This can be viewed in Explorer by clicking Report Explorer Icon.

    Controls Hierarchy

Add Parameter to the Master Report

Let us add the parameter that will be passed to the detail report to display the details accordingly.

  1. From the top right corner of Report Designer, click the Data Dataset Icon icon .

  2. Click Add next to Parameters. A parameter named Parameter1 is added.

  3. Click Parameter1 to edit parameter properties. You can change the Prompt to a more understandable text, such as 'Enter region name'.

    Parameter properties

  4. Go to From Query tab under Available Values and set the following properties - Data Set Name, Value Field, and Label Field, respectively as shown.

    Parameter properties

Note: The name of the parameter in master report and detail report (subreport) should be same.

Bind Data to the Report Controls

  1. Select TextBox1 and enter the following expression in the Value field, Store ID - {StoreID}

  2. Similarly, select TextBox2 and enter the following expression in the Value field, Details for region: {@Parameter1}

Note: The Data Set Name property of the List data region is already set to SalesByRegion data set.

Configure Subreport

Let us embed the parameterized report created in Create Parameterized Report as a detail report and pass the parameter as filter to the detail report data from the master report.


To embed the detail report to master report,

  1. Select Subreport control.

  2. From the Properties pane, set the Report Name property to the detail report's name, that is, 'Details Report'.

    Selecting detail report for the master report

    Note: As you select the Report Name property of Subreport control, you see two Report parameters. It is because the report passed in the Subreport control has two parameters. We will set these parameters later.

We will add two parameters in the master report since the subreport contains two parameters. Parameter1 will be used to filter the region based on the selection from the user prompt. Parameter2 will be used to filter the data based on store id values.

  1. For Parameter1, enter the following expression as the value of the parameter: {@Parameter1}

  2. For Parameter2, enter the following expression as the value of the parameter: {StoreID}

    The report parameters will now look as shown in the following image.

    Parameter properties of Subreport control

To group the details for each store id,

  1. Select the List data region and go to the Properties pane.

  2. In the Group Expressions property, click Show Items and then select Add Item.

  3. Click the radio button to display the fields and select the 'StoreID' field from the list.

    Group Expressions in list data region

Add Page Header

  1. Go to the Report tab on top of the designer and select Add Header option.

    Add Page Header

  2. Drag and drop a TextBox control Textbox Control in the page header area.

  3. Click inside the text box and enter the text 'Customer Orders (Master Detail Report)'.

Customize the Appearance of Master Report

Customized Appearance of Master Report Example

Note: You may need to resize and reposition the controls on the report to accommodate data, and for a cleaner look.

To customize the text boxes with information on store id and details for region,

  1. Set the BACKGROUND - Color property for the page header of the report to '#f1f1f1'.

  2. Align the text in the textboxes using the TEXT - Text Align (Left, Right, Center, and Justify.) and TEXT - Vertical Text Align (Top, Middle, or Bottom) properties. By default, these properties are set to General and Top.

  3. Set the font size for the text in the page header to '14pt' using the TEXT - Font Size property.

  4. Specify the border properties for the textboxes in the table using the BORDER - Width, Border - Style, and BORDER - Color properties. Set the border values to '0.25pt', 'Solid', and '#f1f1f1', respectively.

Preview and Save Report

  1. Click Preview to view your report in the final output. You will be prompted to select the region name.

  2. Select a region and again click Preview .

    See how the parameter passed from master report obtains the details using the subreport control.

  3. Exit the preview mode by clicking Back on the left side of the designer.

  4. Click Save to open the Save dialog box. Enter the report name as 'Master Report' and click Save Report.