Link to home
Start Free TrialLog in
Avatar of nadisha
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(ReportFullName)
  'mcrReport.Database.SetDataSource RstSource   ', 3, 1
 
  mcrReport.Database.SetDataSource 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.OpenSubreport 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.SetDataSource ADOSubReport ', 3, 1
      End If
    Next ReportObject
  Next crxSection
Avatar of Mike McCracken
Mike McCracken

What error are you getting?

mlmcc
Avatar of nadisha

ASKER

Hi,

The code stops at this line:
If ReportObject.Kind = crxSubreportObject.OpenSubreport Then

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=crSubreportObject then

and continue from there

incasan
Avatar of nadisha

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.SetDataSource 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.
     
ASKER CERTIFIED SOLUTION
Avatar of incasan
incasan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is the recordset identical in form to the recordset the report was built against?

mlmcc
Avatar of nadisha

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.