Solved

Subscript out of range error with SetDataSource

Posted on 2003-11-12
1
4,048 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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. …
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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