加载父报表后,您需要将子报表加载到变量中,并将子报表控件的对象属性设置为该变量,然后再运行父报表。例如:
' Load parent report:
Dim rptParent As New ActiveReport
rptParent.LoadLayout App.Path & "\myParentReport.rpx"
' Load the subreport:
Dim rptSubreport As New ActiveReport
rptSubreport.LoadLayout App.Path & "\mySubReport.rpx"
' * Initialize the subreport control by passing the actual report to run as a subreport:
Set rptParentReport.Sections("Detail").Controls("MySubreportControl").Object = rptSubreport
' Preview the parent report in the viewer:
ARViewer21.ReportSource = rptParent
现在,如果您不能硬编码子报表文件名(mySubReport.rpx
在我上面的示例中)或子报表控件名称(MySubreportControl
在我上面的示例中),那么您可以编写一个例程来循环遍历父报表中的所有控件并找到每个子报表控件。然后,确保将子报表文件的名称存储在子报表控件的 ReportName 或 Tag 属性中。然后,您可以在代码中使用子报表控件动态加载/链接子报表文件。如果您需要一些具体的帮助,请在评论中回复您的问题。
此外,ActiveReports 文档的 COM 版本可在此处(存档)在线获得,以防万一有用。
Scott Willeke
GrapeCity