Print Page | Close Window

Coding Sub Reports .NET Crystal Reports 2008

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=10166
Printed Date: 06 May 2024 at 5:40am


Topic: Coding Sub Reports .NET Crystal Reports 2008
Posted By: skysail118
Subject: Coding Sub Reports .NET Crystal Reports 2008
Date Posted: 02 Jun 2010 at 10:46am

We are trying to actively run an applications that automates and produces 21 reports. Everthing works but our report which contains eight subreports. Everything seems to run fine but we receive an "Invalid Index Error"

The following code is provided to see if anyone can spot what we are doinig incorrectly:
 

Dim CRrpt As New ReportDocument()

Dim CRrptTDASub1 As New CrystalDecisions.CrystalReports.Engine.ReportDocument()

 

Case "LH Turbidity Data Analysis Sheet 2 - Page 9"

strFilename = gstrRptLocation & "rptLHWaterTreatmentPlant-NewPage9.rpt"

 

CRrpt.Load(strFilename)

 

Call MainLogin2()

 

CRrpt.SetParameterValue(0, gintRptMonth)

CRrpt.SetParameterValue(1, gintRptYear)

CRrpt.SetParameterValue(2, mstrMonthYearText)

 

                ' ********  SUB REPORT    ********

 

CRrptTDASub2 = CRrpt.OpenSubreport("rptLHWaterTreatmentPlant-NewPage9A")

 

Dim myTableLogOnInfoA As TableLogOnInfo

               

' ********   problem is here ********

è  è   myTableLogOnInfoA = New TableLogOnInfo(CRrptTDASub1.Database.Tables.Item(1).LogOnInfo)

            

Dim myConnectionInfoA As New ConnectionInfo

    myConnectionInfoA.ServerName = gSQLServer

    myConnectionInfoA.UserID = gSQLUser

    myConnectionInfoA.Password = gSQLPW

    myTableLogOnInfoA.ConnectionInfo = myConnectionInfoA

    CRrptTDASub1.Database.Tables.Item(1).ApplyLogOnInfo(myTableLogOnInfoA)

 

    CRrptTDASub1.SetParameterValue(0, gintRptMonth)

    CRrptTDASub1.SetParameterValue(1, gintRptYear)

    CRrptTDASub1.SetParameterValue(2, mstrMonthYearText)

 

  CRViewer1.ReportSource = CRrpt

  CRViewer1.ShowFirstPage()

 

System.Windows.Forms.Cursor.Current =

System.Windows.Forms.Cursors.Default

 

'End of Page 9 Code

 

Private Sub MainLogin2()

 

   Dim crSections As Sections

   Dim crSection As Section

 

   Dim crReportObjects As ReportObjects

   Dim crReportObject As ReportObject

   Dim crSubreportObject As SubreportObject

 

   Dim crReportDocument As New ReportDocument

   Dim crSubreportDocument As ReportDocument

 

   Dim crDatabase As Database

   Dim crTables As Tables

   Dim crTable As Table

 

   Dim myTableLogOnInfo As TableLogOnInfo

   Dim myConnectionInfo As ConnectionInfo

 

        myConnectionInfo = New ConnectionInfo()

 

   With myConnectionInfo

            .DatabaseName = gSQLDatabase

            .ServerName = gSQLServer

            .UserID = gSQLUser

            .Password = gSQLPW

   End With

 

        crDatabase = CRrpt.Database

        crTables = crDatabase.Tables

 

        For Each crTable In crTables

            myTableLogOnInfo = crTable.LogOnInfo

            myTableLogOnInfo.ConnectionInfo = myConnectionInfo

            crTable.ApplyLogOnInfo(myTableLogOnInfo)

        Next

 

        crSections = CRrpt.ReportDefinition.Sections

 

        For Each crSection In crSections

            crReportObjects = crSection.ReportObjects

        For Each crReportObject In crReportObjects

        If crReportObject.Kind = ReportObjectKind.SubreportObject Then

                    crSubreportObject = CType(crReportObject, SubreportObject)

                    crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)

                    crDatabase = crSubreportDocument.Database

                    crTables = crDatabase.Tables

                    For Each crTable In crTables

                        With myConnectionInfo

                            .DatabaseName = gSQLDatabase

                            .ServerName = gSQLServer

                            .UserID = gSQLUser

                            .Password = gSQLPW

                        End With

myTableLogOnInfo = crTable.LogOnInfo

myTableLogOnInfo.ConnectionInfo = myConnectionInfo

crTable.ApplyLogOnInfo(myTableLogOnInfo)

                    Next

                End If

            Next

        Next

    End Sub



-------------
Sky



Print Page | Close Window