Afi83 0 Light Poster

Hi there
I have an application in VB6 I want to use Crystal report (8.5) for reporting. In my application I have a ability to archive part of my database. Then I want to change my database location based on my database name. In my report I have subreport then I search about and find something to loop through all sections of report. The bellow code works fine just for my base database. But when I change database to archive one the report is empty.
The structure of two databases is exactly same then the problem is not there.
But I have to say basic report is based on the basic database then maybe this is the problem that I can't change the database through run time.
Please say me how can I prepare my report in crystal that can show from multiple database names.
Here is code:

Public CrxApp As CRAXDRT.Application
Public CrxRep As CRAXDRT.Report
Public crxSubreport As CRAXDRT.Report
Public crxSubreportObject As SubreportObject
Public crxDatabase As CRAXDRT.Database
Public crxDatabaseTables As CRAXDRT.DatabaseTables
Public crxDatabaseTable As CRAXDRT.DatabaseTable
Public crxSections As CRAXDRT.Sections
Public crxSection As CRAXDRT.Section
Public CRXReportObject As Object

Public Sub DataLoc(DataName As String, REP As String)
    Dim fi As String
    
    
    Set CrxApp = New CRAXDRT.Application
    fi = App.Path & "\" & REP & ".rpt"
    Set CrxRep = CrxApp.OpenReport(fi)

    Set crxSections = CrxRep.Sections
    
    For Each crxSection In crxSections
        For Each CRXReportObject In crxSection.ReportObjects
           If CRXReportObject.Kind = crSubreportObject Then
             Set crxSubreportObject = CRXReportObject
             Set crxSubreport = crxSubreportObject.OpenSubreport
             Set crxDatabase = crxSubreport.Database
             Set crxDatabaseTables = crxDatabase.Tables
             
             For Each crxDatabaseTable In crxDatabaseTables
    'If you are using a  Native connection to PC database
    crxDatabaseTable.Location = App.Path & "\" & DataName & ".mdb"
    
             Next
             
             Set crxSubreport = Nothing
           End If
        Next
    Next
    
    
    'Set crxDatabase = Nothing
    'Set crxDatabaseTable = Nothing
    'Set crxDatabaseTables = Nothing
    'Set crxSections = Nothing
    'Set crxSection = Nothing
    'Set crxSubreportObject = Nothing
   ' Set crxReport = Nothing
   ' Set crxApplication = Nothing
End Sub

After this code I set my crystal viewer to Crxrep and it shows my report on base database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.