Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Coding Sub Reports .NET Crystal Reports 2008 Post Reply Post New Topic
Author Message
skysail118
Newbie
Newbie
Avatar

Joined: 02 Jun 2010
Location: United States
Online Status: Offline
Posts: 1
Quote skysail118 Replybullet Topic: Coding Sub Reports .NET Crystal Reports 2008
    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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.