Solved

Subscript out of range error with SetDataSource

Posted on 2003-11-12
1
4,063 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

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. …
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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