Hi All and thanks for the help in advance. I have been reading thread after thread trying to figure out how to change the database of a Crystal Reports XI at runtime using VS 2002.

This is what I have so far, it seems like a simple thing to do but I keep getting an error on “crxDatabaseTables = crxReport.Database.Tables”

The error reads,
An unhandled exception of type 'System.InvalidCastException' occurred in PTS.exe

Additional information: Specified cast is not valid.

Any help would be appreciated

Thanks Chuck from Las Vegas


Code:
        Dim crxApp As New CRAXDDRT.Application()
        Dim crxReport As CRAXDDRT.Report
        Dim ReportName As String
        Dim crxDatabaseTable As CRAXDDRT.DatabaseTable

        Dim crxDatabaseTables As Tables

        crxApp = CreateObject("crystalruntime.application.11") 

        ReportName = System.Windows.Forms.Application.StartupPath & "\" & Frm1.CBReports.SelectedValue

        crxReport = crxApp.OpenReport(ReportName)

        crxDatabaseTables = crxReport.Database.Tables

        For Each crxDatabaseTable In crxDatabaseTables
            crxDatabaseTable.Location = System.Windows.Forms.Application.StartupPath & "\" & Frm1.FileText
        Next crxDatabaseTable

        CrystalReportViewer.ReportSource = crxReport