Solved

Subscript out of range error with SetDataSource

Posted on 2003-11-12
1
4,022 Views
Last Modified: 2011-10-03
I'm using VB6 SP5 with Crystal 9 SP2. I'm trying to set my Data Source at runtime and keep getting an "Error 9, Subscript out of range". We've created a .dll that pulls the dataset information from the registry. We've defined this information and use the moRS recordset for many other functions in the program so we know it'll work. Even if I simplify things and define the recordset I continue to get the same "subscript out of range error". The code in my module is as follows:

Set Report = New CrystalReport2
    Set moRS = New ADODB.Recordset
    strSQL = "SELECT [tblPlant].[PlantID] "
    strSQL = strSQL & "FROM tblPlant;"
    Report.DiscardSavedData
    If goDataConn.DataOpen Then
        moRS.Open strSQL, goDataConn.Connection, adOpenForwardOnly, adLockReadOnly
        lngTableCount = Report.Database.Tables.Count
        CRViewer91.ReportSource = Report
        CRViewer91.ViewReport
        Report.Database.SetDataSource moRS
        For lngIndex = 1 To lngTableCount
            With Report.Database
                .Tables(lngIndex).SetDataSource moRS
            End With
        Next
        'Report.Database.AddADOCommand goDataConn.Connection, rsCommand
        Report.AutoSetUnboundFieldSource crBMTNameAndValue
        goDataConn.DataClose
    End If
    Set moRS = Nothing
0
Comment
Question by:deepphee
1 Comment
 
LVL 13

Accepted Solution

by:
EwaldL earned 500 total points
ID: 9736057
You need to pass the dataset before viewing the report. I guess that for testing you have made the recordset as simple as possible using 1 field only? Try the following:

Replace this bit:

 lngTableCount = Report.Database.Tables.Count
        CRViewer91.ReportSource = Report
        CRViewer91.ViewReport
        Report.Database.SetDataSource moRS
        For lngIndex = 1 To lngTableCount
            With Report.Database
                .Tables(lngIndex).SetDataSource moRS
            End With
        Next

with this
 Report.Database.Tables(1).SetDataSource moRS, 3
 CRViewer91.ReportSource = Report
 CRViewer91.ViewReport

also remove the
Report.AutoSetUnboundFieldSource crBMTNameAndValue

Also, the report must have been created in the right way. I prefer OLE DB. The recordset also has to match the data structure that was used at design time

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now