Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subreports with recordsets

Status
Not open for further replies.

shavon

Programmer
Jun 18, 2001
102
CA
Hello:

I am using the following code to load a report and several sub reports. The main report displays correctly, however, the sub reports do not display at all, not even when I try to load just 1. I have tried different combinations with no positive result. Any help would be greatly appreciated. Thanks.


Private Sub LoadReport()
Screen.MousePointer = vbHourglass
Dim rsMain As ADODB.Recordset
Set rsMain = New ADODB.Recordset
Dim rsCourier As ADODB.Recordset
Set rsCourier = New ADODB.Recordset
Dim rsMisc As ADODB.Recordset
Set rsMisc = New ADODB.Recordset

rsMain.Open app.Path & "\rsDetailMain.rs", , , , adCmdFile
Report.Database.SetDataSource rsMain, 3, 1
Report.ReadRecords
rsCourier.Open app.Path & "\rsDetailCourier.rs", , , , adCmdFile
Set crxSubreport = Report.Subreport1.OpenSubreport
crxSubreport.Database.SetDataSource rsCourier, 3, 1

Set crxSubreport = Report.Subreport2.OpenSubreport
crxSubreport.Database.SetDataSource rsCourier, 3, 1
Report.ReadRecords
rsMisc.Open app.Path & "\rsDetailMisc.rs", , , , adCmdFile
Set crxSubreport = Report.Subreport3.OpenSubreport
crxSubreport.Database.SetDataSource rsMisc, 3, 1
Report.ReadRecords
Set crxSubreport = Report.Subreport4.OpenSubreport
crxSubreport.Database.SetDataSource rsMisc, 3, 1
Report.ReadRecords

Set rsMain.ActiveConnection = Nothing
Set rsCourier.ActiveConnection = Nothing
Set rsMisc.ActiveConnection = Nothing

CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
End Sub
 
Hi shavon,

The way you try to access subreport maybe not correct. I saw this kind of code before. But not sure it works or not.

maybe you can try code below:

'Get Report Section collection object
Set RptSection = Session("oRpt").sections

'SetLogonInfo for each subreport inside main report

For Each CRXSection In RptSection
Set CRXReportObjects = CRXSection.ReportObjects
For Each CRXReportObject In CRXReportObjects
If CRXReportObject.Kind = 5 Then 'crSubreportObject
If DeclineAction <> &quot;&quot; then exit for
Set CRXSubreportObj = CRXReportObject
Set CRXSubreport = CRXSubreportObj.OpenSubreport
For i = 1 To CRXSubreport.Database.Tables.Count
' response.write CRXSubreport.Database.Tables(i).name & &quot;<br/>&quot;
CRXSubreport.Database.Tables(i).SetLogOnInfo Cstr(DSNName), Cstr(ServerName), Cstr(UserID), Cstr(Passwrod)
' CRXSubreport.Database.Tables(i).Location = Cstr(ServerName) & &quot;..&quot; & CRXSubreport.Database.Tables(i).Name
Next
End If
Next
Next

also, subreport is linked subreport or unlinked subreport? you also need to pass parameters required by subreport if it's unlinked subreport.

still have problems? just let me know.

Cheers!

Ted

ted_liu@canadalife.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top