Data Connectivity
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Data Connectivity
Message Icon Topic: Dynamically change my database name Post Reply Post New Topic
Author Message
Afi83
Newbie
Newbie


Joined: 08 Oct 2009
Online Status: Offline
Posts: 7
Quote Afi83 Replybullet Topic: Dynamically change my database name
    Posted: 20 Oct 2009 at 10:28pm
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.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 23 Oct 2009 at 6:39am
I am leery of any code that creates fields or changes items in a report.  Have you tried to changed the location/name/schema of a database in the report using the IDE?  It's not easy, and sometimes doesn't work the first time, so I would be doubtful that you can change the name / location of database. 
 
A simpler method, which I have seen done successfully, though don't care for, is to change the ODBC connection to point to the database that you want.
 
The best method, IMO, is to create the dataset in your application and then to push it the report.  The report doesn't know, and doesn't care where the data came from, just that the schema matches and the data is there.  The report is happy, the user is happy because the correct data is in the report, and this whole issue is moot.
 
HTH
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.