1
votes

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
It is possible and here is an answer for VB.NET that demonstrates the technique. stackoverflow.com/questions/9195344/…jac
Do you know of an example with VB6?Zingo
Post your code with your specific problem and I'm sure you will get help.jac

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