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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having trouble calling a report with subreports from .Net

Status
Not open for further replies.

Salthead

Programmer
Feb 25, 2003
7
US
I cobbled together this code from postings on the web. It blows with an "Object reference not set to an instance of an object" for crReportObject.Kind. What am I doing wrong?



Public Function RunCrystalReport2(ByVal strReportName As String _
, ByVal colparam As Collection _
, ByVal strSessionId As String) _
As Boolean
Dim crReportDocument As New ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
Dim crTableLogoninfos As New TableLogOnInfos
Dim crTableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crConnectionInfo2 As New ConnectionInfo
Dim crDatabase As Database
Dim CrTables As Tables
Dim CrTable As Table
Dim crReportObject As ReportObject
Dim crReportObjects As ReportObjects
Dim crSubReport As ReportDocument
Dim crSubReportObject As SubreportObject
Dim crSections As Sections
Dim crSection As Section
Dim TableCounter
Dim param As New ParameterDiscreteValue
Dim values As New ParameterValues
Dim strFileName As String
'Dim strReportPath As String = "c:\Inetpub\ Dim strReportPath As String = ConfigurationSettings.AppSettings("rootpath")
Dim strAdobeFileName As String
Dim strParam As String

strReportName = strReportPath & strReportName
strAdobeFileName = ConfigurationSettings.AppSettings("exportpath") & strSessionId & ".pdf"

If File.Exists(strReportName) Then
' Setup export to PDF
crReportDocument.Load(strReportName)
With crConnectionInfo
.ServerName = "SqlServer1"
.DatabaseName = "db1"
.UserID = "User1"
.Password = "Pwd1"
End With
With crConnectionInfo2
.ServerName = "SqlServer2"
.DatabaseName = "User2"
.UserID = "db2"
.Password = "Pwd2"
End With
'This code works for both user tables and stored
'procedures. Set the CrTables to the Tables collection
'of the report

CrTables = crReportDocument.Database.Tables

'Loop through each table in the report and apply the
'LogonInfo information

For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
'mine ends
crSections = crReportDocument.ReportDefinition.Sections
'Loop through each section and find all the report objects
'Loop through all the report objects
'to find all subreport objects, then set the
'logoninfo to the subreport
Dim intA As Integer
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
'If you find a subreport, typecast
'the reportobject to a subreport object
crSubReportObject = CType(crReportObject, SubreportObject)
'Open the subreport
crReportDocument = _
crSubReportObject.OpenSubreport(crSubReportObject.SubreportName)
crDatabase = crReportDocument.Database
CrTables = crDatabase.Tables
'Loop through each table and set the connection info
'Pess the connection info
'to the logoninfo object then apply the
'logoninfo to the subreport
For Each CrTable In CrTables
crTableLogoninfo = CrTable.LogOnInfo
crTableLogoninfo.ConnectionInfo = crConnectionInfo2
CrTable.ApplyLogOnInfo(crTableLogoninfo)
Next
End If
Next
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top