Lets say i have two Databases with the same tables. I would like to be able to keep the same crystal report but change the DataSource on the fly from one Database to Another. Is this even possible? As of now im using VB6 and the crystal reports are accessed through a path stored in a database. Is there a connection string you could dynamically alter that would change the Database a specific Report is looking at? Thanks
1
votes
1 Answers
0
votes
Try something like:
Dim ObjApp as new Craxdrt.application
Dim ObjRep as new Craxdrt.report
Dim Con as new ADODB.Connection
Dim Rs as new ADODB.Recordset
Private sub form_Load() 'Or try to put it in a onClick() event, too
Dim ds as string
'Here you can change the datasource. Replace C:\Data.mdb
if SomethingYouNeed=True
ds="C:\Data.mdb"
else
ds="C:\AnotherData.mdb"
end if
Con.Open "Provider=Microsoft.Jet.Oledb.4.0; Datasource=" & ds
Rs.open "Select * from Client Where ClientName = 'Alfred'",con,AdopenStatic,AdlockOPtimistic
set objrep = objapp.open("C:\client.rpt")
objrep.Database.SetDatasource Rs
CrViewer.reportsource = objrep
CrViewer.ViewReport
End sub