nadisha
asked on
HELP!! Opening subreports in VB and opening it with Crystal Reports
Help!
VB is v6.0 and Crystal Reports is v9.0.
I am passing a stored procedure from Oracle into Visual Basic. I have a Crystal Report with one main report and 4 subreports. I want to be able to open the subreports in Visual Basic. I found some sample code from Crystal Reports web site and integrated it into my code. Here is it, but I am getting an error. Can someone help me please? Its really important, but isn't everything =).
Public Function PrintReport(ByVal ReportFullName As String, _
ByVal RstSource As ADODB.Recordset) As Boolean
'Sub-reports
Dim srpX As CRAXDDRT.report ' Loop report object.
Dim strReportName As String
Screen.MousePointer = vbHourglass
Dim report As New CRAXDRT.report
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim ReportObject As Object
Dim crxReportObjects As CRAXDRT.ReportObjects
Dim crxSubreportObject As CRAXDRT.SubreportObject
Dim crxSubObj As CRAXDRT.SubreportObject
Dim crxSubReport As CRAXDRT.report
Dim ADOMainReport As ADODB.Recordset
Dim ADOSubReport As ADODB.Recordset
'SetPrivateData
'Set crxSections = report.Sections
Set mcrReport = mcrApp.OpenReport(ReportFu llName)
'mcrReport.Database.SetDat aSource RstSource ', 3, 1
mcrReport.Database.SetData Source ADOMainReport ', 3, 1
Set crxSections = mcrReport.Sections 'get the sections from the main rpt
'go through each section in the main report
For Each crxSection In crxSections
'get all the objects in this section
Set crxReportObjects = crxSection.ReportObjects
'go through each object in the reportobjects for this section
For Each ReportObject In crxReportObjects
'find which one is the subreport
If ReportObject.Kind = crxSubreportObject.OpenSub report Then
'found a subreport, get it
Set crxSubObj = ReportObject
'open the subreport
Set crxSubReport = crxSubObj.OpenSubreport
'pass the 2nd recordset to the subreport
crxSubReport.Database.SetD ataSource ADOSubReport ', 3, 1
End If
Next ReportObject
Next crxSection
VB is v6.0 and Crystal Reports is v9.0.
I am passing a stored procedure from Oracle into Visual Basic. I have a Crystal Report with one main report and 4 subreports. I want to be able to open the subreports in Visual Basic. I found some sample code from Crystal Reports web site and integrated it into my code. Here is it, but I am getting an error. Can someone help me please? Its really important, but isn't everything =).
Public Function PrintReport(ByVal ReportFullName As String, _
ByVal RstSource As ADODB.Recordset) As Boolean
'Sub-reports
Dim srpX As CRAXDDRT.report ' Loop report object.
Dim strReportName As String
Screen.MousePointer = vbHourglass
Dim report As New CRAXDRT.report
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim ReportObject As Object
Dim crxReportObjects As CRAXDRT.ReportObjects
Dim crxSubreportObject As CRAXDRT.SubreportObject
Dim crxSubObj As CRAXDRT.SubreportObject
Dim crxSubReport As CRAXDRT.report
Dim ADOMainReport As ADODB.Recordset
Dim ADOSubReport As ADODB.Recordset
'SetPrivateData
'Set crxSections = report.Sections
Set mcrReport = mcrApp.OpenReport(ReportFu
'mcrReport.Database.SetDat
mcrReport.Database.SetData
Set crxSections = mcrReport.Sections 'get the sections from the main rpt
'go through each section in the main report
For Each crxSection In crxSections
'get all the objects in this section
Set crxReportObjects = crxSection.ReportObjects
'go through each object in the reportobjects for this section
For Each ReportObject In crxReportObjects
'find which one is the subreport
If ReportObject.Kind = crxSubreportObject.OpenSub
'found a subreport, get it
Set crxSubObj = ReportObject
'open the subreport
Set crxSubReport = crxSubObj.OpenSubreport
'pass the 2nd recordset to the subreport
crxSubReport.Database.SetD
End If
Next ReportObject
Next crxSection
ASKER
Hi,
The code stops at this line:
If ReportObject.Kind = crxSubreportObject.OpenSub report Then
This is the error message:
Object variable or With block variable not set
Thanks
nadisha
The code stops at this line:
If ReportObject.Kind = crxSubreportObject.OpenSub
This is the error message:
Object variable or With block variable not set
Thanks
nadisha
the reportobject.kind is a property of the report.
You are trying to open a report into a property.
Try the following:
if ReportObject.Kind=crSubrep ortObject then
and continue from there
incasan
You are trying to open a report into a property.
Try the following:
if ReportObject.Kind=crSubrep
and continue from there
incasan
ASKER
Thanks Incasan.
I was able to step through this. Now it stops at this line:
'pass the 2nd recordset to the subreport
crxSubReport.Database.SetD ataSource ADOSubReport,3,1
The error message is as follows:
Subscript out of range.
Does this have something to do with the "ADOSubReport,3,1"?
Thanks again.
I was able to step through this. Now it stops at this line:
'pass the 2nd recordset to the subreport
crxSubReport.Database.SetD
The error message is as follows:
Subscript out of range.
Does this have something to do with the "ADOSubReport,3,1"?
Thanks again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is the recordset identical in form to the recordset the report was built against?
mlmcc
mlmcc
ASKER
I have one recordset that returns the values for the main form. What I need to know is how to pass 3 more recordsets in VB so that the data will show up in the 3 subreports. Hope this makes sense. Thanks.
mlmcc