Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-04-01
7
Medium Priority
?
600 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:nadisha
  • 3
  • 2
  • 2
7 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 8248115
What error are you getting?

mlmcc
0
 

Author Comment

by:nadisha
ID: 8248158
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
0
 
LVL 1

Expert Comment

by:incasan
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

incasan
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:nadisha
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.
     
0
 
LVL 1

Accepted Solution

by:
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.

incasan
0
 
LVL 101

Expert Comment

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

mlmcc
0
 

Author Comment

by:nadisha
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.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

571 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