Solved

Subscript out of range error with SetDataSource

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

21 Experts available now in Live!

Get 1:1 Help Now