Dynamically Assign DB Source for Crystal Reports?

Winston

Well-known member
Joined
Jan 25, 2003
Messages
266
Location
Sydney, Australia
Ive played around with just setting one CP object up, but say for example i want to dynamically change the location of the source of the database, how do i go about doing this?

Thanks.
 
I havent tested this code, but I believe you should be able to set the data source as follows:

Code:
Initialize the new database connection for the new data source
Dim DbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyDatabase.mdb")

Initialize a new ReportDocument class variable
Dim crReportDocument As New ReportDocument

Initialize the report you are going to use, renaming CrystalReport1 to the name of your report
Dim MyReport As New CrystalReport1   

Set the new datasource for the ReportDocument and load the report
crReportDocument.SetDataSource(dbconn)
crReportDocument.Load(MyReport)

I think the only thing that youll need to be sure of is that the tables fields that the report uses are available in both databases. If not, youll probably get an error when you view or print the report.

Let me know how it works out

Chris
 
Back
Top