水晶报表子报表仅字段定义无法显示数据的问题
我有一个报表中包含一个子报表,子报表使用了仅字段定义来定义报表字段,在单独测试子报表时能显示数据,但和主报表结合后子报表数据不显示。
编程环境:vb6+水晶报表9
以下是单独测试子报表的代码,能正常显示数据:
Dim props As CRAXDRT.ConnectionProperties '报表数据源参数集
Dim prop As CRAXDRT.ConnectionProperty '报表数据源参数
'通过sql语句查询获取的记录集
Set rs = m_CustomPacking.ShowCustomPackingPrint(R_PRID)
Screen.MousePointer = vbHourglass
Set oRptSub = oApp.OpenReport(ReportName, 1)
'加载报表字段定义文件
Set props = oRptSub.Database.Tables(1).ConnectionProperties
For Each prop In props
prop.Value = App.Path & "\report\m_custompacking.ttx"
Exit For
Next
oRptSub.Database.SetDataSource rs
oRptSub.ReadRecords
但只将以上代码与与主报表结合则子报表不会显示数据,我不知道如何才能与主报表结合来显示数据,烦请各位高手帮忙,谢谢!
[解决办法]
用过的一段代码。看看有用不
Dim crxTable As CRAXDRT.DatabaseTable
Dim crxReportObject As Object
Dim crxSubReportOject As CRAXDRT.SubreportObject
Dim crxSubReport As CRAXDRT.Report
Dim crxSection As CRAXDRT.Section
Dim strLocation As String
For Each crxSection In crxReport.Sections
For Each crxReportObject In crxSection.ReportObjects
If crxReportObject.Kind = crSubreportObject Then
Set crxSubReportOject = crxReportObject
Set crxSubReport = crxSubReportOject.OpenSubreport
For Each crxTable In crxSubReport.Database.Tables
'switch to passed database, instance sever
crxTable.SetLogOnInfo objApplication.User.dbinstance, _
objApplication.User.dbDatabase, _
UnixBillPrintLogin, _
UnixBillPrintPassword
strLocation = StripDatabaseAndOwner(crxTable.Location)
crxTable.SetTableLocation strLocation, "", ""
Next crxTable
End If
Next crxReportObject
Next crxSection