As of ActiveReports 12, you can use SubReport controls in a Page Report. Page report types are great for creating highly structured reports like billing statements, forms, and catalogs. Because you place data regions directly in the page, Page Reports eliminate the need to use code or measurements to make sure everything fits. The data regions in a Page Report are designed to hold their size and position: they don't grow or shrink at run time, so the result is very much a WYSIWYG report.

Download the sample rdlx files

In this blog, we’ll create an invoice using two reports. The main report functions much like a template and includes the company logo, date, address, and a payment stub to be returned with the payment. We’ll use a SubReport control to include the details of the customer’s purchase. By using a SubReport in this scenario, the template can easily be re-used for other purposes.

Step 1. Creating the Template

We want to create a template that looks something like this:

Sample report

First, let's create a Page Report in the ActiveReports designer. In the Report Explorer, add a Data Source to connect to the Reels Database, and then add a “Customers_List” Data Set to bring in our desired fields:

Add the data source in the report explorer

Add the company logo as an embedded image.

Next, from the ToolBox, place an Image control, a series of TextBoxes, and Containers in the top portion of the page on the design surface. Use the Field Selection Adorners to bind each TextBox to a field in our Customers_List data set.

For the Payment Stub portion, place a container control at the bottom of the page. Inside the container, place our logo and a series of TextBoxes for our address, the customer’s address, account number, etc. Again, bind the TextBoxes to the respective fields from our data set, and adjust their sizes.

Step 2. Add a SubReport Control

From the ToolBox, drag a SubReport control and drop it in the middle of the page. We’ll resize it to an appropriate height and width within the page. This SubReport control will be used to bring in another report that details the customer’s purchases. This ‘child’ report has a tabular layout:

Subreport layout

We need to bind the SubReport control to the child report using the “ReportName” property of the SubReport control in the Properties window. Here, we can select a report file either from the ActiveReports Server or a file directory.

Step 3. Pass a Parameter

To ensure that the child report lists the right customer’s purchase order in the template, we need to pass a parameter from the template to the child report. This parameter is the “SaleID” for the particular sale for which we're creating the statement.

First, add a hidden parameter in the child report named “SalesID”, and then modify the query in the child report to filter the data based on the parameter being passed.

Next, go back to the template report and select the SubReport control. In the Properties window, click on the ellipses next to “Parameters”. In the resulting “Subreport – Parameters” dialog box, add a parameter and set its value to the SaleID field from our Customers_List data set.

Parameters

NOTE: It's important to ensure that the Parameter Name here matches the name given to the parameter in the child report.

Step 4. Account for Overflow

The last step is to account for cases where the purchase order exceeds the allotted space of the SubReport control. In these cases, because the SubReport control cannot grow, the child report would be cut short and some rows wouldn't display.

To account for these scenarios, add a second page to the template where we can show the overflow from the SubReport control. At the bottom of the designer window, click on “New” to create a new page:

Create a new page

On Page 2, drag an OverflowPlaceHolder control from the ToolBox and stretch it to fill the page. Rename the OverflowPlaceHolder control to SubReportOverFlow. Next, click on the white margins of the page to select Page 2, and, in the Properties window, set ThrowIfPlaceHoldersEmpty to true. This discards a blank, or empty, page 2 if the child report doesn't need to overflow to page 2.

Now, we connect the SubReport control to the OverflowPlaceHolder control so the SubReport knows where to go to display the extra content. Select the SubReport control, and, in the Properties window, set the OverflowName Property to SubReportOverFlow.

Step 5. Preview the Page Report with Subreport

At this point, we’re done. On Preview, our report should look like this:

Page report with subreport

Note: To run the samples, please make sure that you edit the Reels Data source connection strings of both report files to point to your copy of the Reels database. If you have ActiveReports installed, the Reels database will be installed in your <user>\Documents\GrapeCity Samples\ActiveReports 12\Data directory.

Download the sample rdlx files

Try ActiveReports Developer