ActiveReports 8 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Page Report Walkthroughs > Layout > Subreport in a CPL Report |
You can create a CPL report that contains a subreport. This walkthrough illustrates how to create a report using a subreport.
The walkthrough is split up into the following activities:
Note: This topic uses the Employee, Sale and SaleDetails tables in the Reels database. By default, in ActiveReports, the Reels.mdb file is located at [User Documents folder]\ComponentOne Samples\ActiveReports 8\Data\Reels.mdb. |
On completing this walkthrough you get a layout that looks similar to the following at design time and at run time.
To add a report for the subreport
See Adding an ActiveReport to a Project for information on adding different report layouts.
To connect the subreport to a data source
OR
Select Add Data Source on the Report Explorer using the Add button drop-down.
Enter a name for the data source in the Name field in Report Data Source Dialog, for example, SubReels.
To add a report parameter to the subreport
OR
Select Parameter from the Add button drop-down.
To add a dataset with a parameter to the subreport
Add a parameter to the Parameters tab when adding a query parameter using the syntax required by your database. This will ensure that the parameter value is passed to the query from the Report Parameters collection.
OR
Select Data Set from the Add button drop-down.
SQL Query |
Copy Code
|
---|---|
SELECT * FROM EmployeeSales |
To add controls to display data on the subreport
Column | Width |
---|---|
First | 1.35in |
Second | 1.35in |
Third | 1.35in |
Fourth | 1.35in |
Tip: Usually it is easier to resize existing columns before adding new columns. This prevents the table from growing horizontally and pushing the report width beyond what fits on paper. |
Note: You can change the name of a table group only after you have set the expression. |
To add data fields to the Table data region
Data Field | Column Name | Property Name |
---|---|---|
Name | TableColumn1 | FontWeight: Bold |
Tip: It is often helpful to use colors when designing a report. Colors make identification of the various sections easier for troubleshooting while previewing. |
Value | Column Name | Property Name |
---|---|---|
Sale Date | TableColumn1 | FontWeight: Bold TextAlign: Right |
Sale Number | TableColumn2 | FontWeight: Bold TextAlign: Right |
Quantity | TableColumn3 | FontWeight: Bold TextAlign: Right |
Total | TableColumn4 | FontWeight: Bold TextAlign: Right |
Data Field | Column Name | Property Name |
---|---|---|
SaleDate | TableColumn1 | Format: Short date |
SaleID | TableColumn2 | |
Quantity | TableColumn3 | |
Total | TableColumn4 | Format: Currency |
Data Field | Column Name | Property Name |
---|---|---|
Quantity | TableColumn3 | |
Total | TableColumn4 | Format: Currency |
Value | Column Name | Property Name |
---|---|---|
Employee Total: | TableColumn2 | FontWeight: Bold TextAlign: Right |
Design Time Layout | Runtime Layout | ||
---|---|---|---|
|
|
To create the main report
To connect the main report to a data source
OR
Select Add Data Source on the Report Explorer using the Add button drop-down.
Enter a name for the data source in the Name field in Report Data Source Dialog, for example, MainReels.
To add a dataset to the main report
Right-click the Data Source node in the Report Explorer and select the Add Data Set option
OR
Select Data Set from the Add button drop-down.
Enter a name for the dataset on the General page in the DataSet Dialog, for example, EmployeeInfo. This dataset is a child node to the data source icon in the Report Explorer.
Enter the following SQL query in the Query field on the Query tab of this dialog:
SQL Query |
Copy Code
|
---|---|
SELECT * FROM EmployeeInfo |
To add controls to display data on the main report
The following steps demonstrate how you can add controls and create the main report:
To add a static label to the top of the main report
Drag a TextBox control from the toolbox onto the body of the report and set the following properties:
Property Name | Property Value |
---|---|
Font | Normal, Arial, 14pt, Bold |
Location | 0in, 0in |
Size | 6.25in, 0.375in |
TextAlign | Center |
Value | Employee Report by City and Store |
BackgroundColor | Lavender |
To add a List data region that repeats data for each city
Property Name | Property Value |
---|---|
BackgroundColor | Silver |
DataSetName | EmployeeInfo |
Location |
0in, 0.375in |
Size | 6.25in, 3in |
Property Name | Property Value |
---|---|
FontSize | 12pt |
Location | 0in, 0in |
Size | 6.25in, 0.25in |
TextAlign | Center |
To nest a second List data region that repeats data for each store within the city
Property Name | Property Value |
---|---|
BackgroundColor | LightSteelBlue |
DataSetName | EmployeeInfo |
Location | 0.125in, 0.25in |
Size | 6in, 2.625in |
Property Name | Property Value |
---|---|
FontWeight | Bold |
Location | 0in, 0in |
Size | 2in, 0.25in |
To nest a third List data region that repeats data for each employee in the store
Property Name | Property Value |
---|---|
BackgroundColor | White |
DataSetName | EmployeeInfo |
Location | 0.125in, 0.25in |
Size | 5.75in, 2.25in |
Data Field | Property Name |
---|---|
Name |
Location: 1in, 0in |
Education | Location: 1in, 0.25in Size: 2.25in, 0.25in |
DateOfBirth |
Location: 4.25in, 0in |
PhoneNumber | Location: 4.25in, 0.25in Size: 1.5in, 0.25in |
TextBox Name | Value Property | Property Name |
---|---|---|
TextBox 1 | Name: |
Location: 0in, 0in |
TextBox 2 | Education: | Location: 0in, 0.25in Size: 1in, 0.25in FontWeight: Bold |
TextBox 3 | Date of Birth: |
Location: 3.25in, 0in |
TextBox 4 | Phone: | Location: 3.25in, 0.25in Size: 1in, 0.25in FontWeight: Bold |
TextBox 5 | Sales Record | Location: 0in, 0.5in Size: 1.25in, 0.25in FontWeight: Bold |
To add a Subreport control to the main report
Property Name | Property Value | ||
---|---|---|---|
Location | 0.125in, 0.75in | ||
NoRows | No sales recorded for this employee during 2005. | ||
ReportName |
Sales (ensure that this report is saved in the same directory as the Sales report)
|
||
Size | 5.5in, 1.25in | ||
Visibility: Hidden | True (hides the subreport initially) | ||
Visibility: ToggleItem | Sales Record text box added in the previous procedure (puts a toggle image next to the text that shows the subreport when clicked) |
Note: You can use the option of having the subreport automatically apply the same theme as the hosting report. This option is available on the General page of the Subreport Properties. |
To view the report
OR
Note: Click the + to the left of Sales Record to see the subreport. |