To embed a subreport into a parent report, you add two reports to a Visual Studio project, and from the ActiveReports toolbox, drag the SubReport control onto one of the reports. You can then add code to create an instance of the child report, and to display it in the SubReport control.
To add code to create an instance of the child report
![]() |
Warning: Do not create a new instance of the subreport in the Format event. Doing so creates a new subreport each time the section Format code is run, which uses a lot of memory. |
To write the code in Visual Basic
- At the top left of the code view for the parent report, click the drop-down arrow and select (rptYourParentReportName Events).
- At the top right of the code window, click the drop-down arrow and select ReportStart. This creates an event-handling method for the report's ReportStart event.
- Add code to the handler to create a new instance of the child report.
The following example shows what the code for the method looks like.
| Visual Basic.NET code. Paste JUST ABOVE the ReportStart event. | Copy Code |
|---|---|
Dim rpt As rptYourChildReportName | |
| Visual Basic.NET code. Paste INSIDE the ReportStart event. | Copy Code |
|---|---|
rpt = New rptYourChildReportName() | |
- Click in the gray area below the parent report to select it.
- Click the events icon in the Properties Window to display available events for the report.
- Double-click ReportStart. This creates an event-handling method for the report's ReportStart event.
- Add code to the handler to create a new instance of the child report.
The following example shows what the code for the method looks like.
| C# code. Paste JUST ABOVE the ReportStart event. | Copy Code |
|---|---|
private rptYourChildReportName rpt; | |
| C# code. Paste INSIDE the ReportStart event. | Copy Code |
|---|---|
| rpt = new rptYourChildReportName(); | |
To add code to display the child report in a subreport control on a parent report
- Double-click in the detail section of the design surface of the parent report to create a detail_Format event.
- Add code to the handler to display a report in the subreport control.
To write the code in Visual Basic
The following example shows what the code for the method looks like.
| Visual Basic.NET code. Paste INSIDE the Format event. | Copy Code |
|---|---|
Me.SubReport1.Report = rpt | |
The following example shows what the code for the method looks like.
| C# code. Paste INSIDE the Format event. | Copy Code |
|---|---|
| this.subReport1.Report = rpt; | |
Hide All