HELP!! Opening subreports in VB and opening it with Crystal Reports

Posted on 2003-04-01
Medium Priority
Last Modified: 2012-08-14
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

  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
  '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
Question by:nadisha
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 101

Expert Comment

ID: 8248115
What error are you getting?


Author Comment

ID: 8248158

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



Expert Comment

ID: 8259736
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.


Author Comment

ID: 8260762
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.

Accepted Solution

incasan earned 300 total points
ID: 8261049
possibly. I take it the ADOSubReport is valid recordset. And the 3 is a fixed number (for some reason is the only possible value).

It is the 1 at the end that worries me. It applies to an index of the table that is actually linked to the report. In other words, is there a table in your subreport that would link to index 1 ?

My tip would be, try to vary a bit with this and you should be able to come up with the correct index number.

LVL 101

Expert Comment

ID: 8266512
Is the recordset identical in form to the recordset the report was built against?


Author Comment

ID: 8283137
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.


Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question