Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4131
  • Last Modified:

Subscript out of range error with SetDataSource

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
deepphee
Asked:
deepphee
1 Solution
 
EwaldLCommented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now