[RESOLVED] Changing Datasource in VB6 using Crystal
I am trying to change the datasource for a crystal report in VB6 and it still looks at the report datasource when it was built. I am trying to use the code
report.database.setdatasource e:\ware.mdb,3,1
It is still trying to find it in the old location when the report was built.
e:\ware\ware.mdb
I am trying to change this on the fly so that I can place the database anywhere and just change the location in an INI file which the VB program reads on startup.
Thanks.
Re: Changing Datasource in VB6 using Crystal
I dont think you can pass the mdb location for the datasource. You need to pass an ADO recordset as the Datasource like you posted. Check my example in my signature - VB6/CR Ex.
Moved from Classic VB forum.
Re: Changing Datasource in VB6 using Crystal
Welcome to the forums. :wave:
You need to pass the a recordset as Rob indicates.
Re: Changing Datasource in VB6 using Crystal
Quote:
Originally Posted by RobDog888
I dont think you can pass the mdb location for the datasource. You need to pass an ADO recordset as the Datasource like you posted. Check my example in my signature - VB6/CR Ex.
Moved from Classic VB forum.
Your code did not show up. could you please post it.
Re: Changing Datasource in VB6 using Crystal
Maybe you have a popup blocker? Anyways here is a copy of the links code.
VB Code:
Option Explicit
'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
'Add reference to Crystal Reports Viewer Control
'Add reference to Microsoft ActiveX Data Objects 2.x Library
'oCnn = current open ADO connection object
Private Sub Command1_Click()
Dim oApp As CRAXDRT.Application
Dim oReport As CRAXDRT.Report
Dim oRs As ADODB.Recordset
Dim sSQL As String
sSQL = "SELECT * FROM Table1"
Set oRs = New ADODB.Recordset
Set oRs = oCnn.Execute(sSQL)
Set oApp = New CRAXDRT.Application
Set oReport = oApp.OpenReport(App.Path & "\MyReport.rpt", 1)
oReport.Database.SetDataSource oRs, 3, 1 '<--Pass an ADO Recordset here
crvMyCRViewer.ReportSource = oReport
crvMyCRViewer.ViewReport
End Sub
Re: [RESOLVED] Changing Datasource in VB6 using Crystal
Ok, What if we want to change the whole SQL database ? Preferable using ODBC connection?
e.g If design time used Connection "ODBC1" and on run time it should use "ODBC2"? I am using CR XI.
Thanks.
Re: Changing Datasource in VB6 using Crystal
Quote:
Originally Posted by RobDog888
Maybe you have a popup blocker? Anyways here is a copy of the links code.
VB Code:
Option Explicit
'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
'Add reference to Crystal Reports Viewer Control
'Add reference to Microsoft ActiveX Data Objects 2.x Library
How do I do this??!?!?!? I can't figure it out, PLEASE HELP!
Re: [RESOLVED] Changing Datasource in VB6 using Crystal
For line 1 and 3...
Project > References... > check/select each reference > click Ok.
For line 2...
Project > Components > Controls tab > check/select CR Viewer Control > click OK.
Re: [RESOLVED] Changing Datasource in VB6 using Crystal
I change the database location of Crystal reguarly using VB and Aceess databases. It wis different between verison 8 of Crystal and versions newer then that. If you would like an example let me know and I' post them.
Re: [RESOLVED] Changing Datasource in VB6 using Crystal
Quote:
Originally Posted by GaryMazzone
I change the database location of Crystal reguarly using VB and Aceess databases. It wis different between verison 8 of Crystal and versions newer then that. If you would like an example let me know and I' post them.
If you could post examples that would help out a ton!
Re: [RESOLVED] Changing Datasource in VB6 using Crystal
hi... how about changing datasources using data report? does anybody know?? pls help??
Re: [RESOLVED] Changing Datasource in VB6 using Crystal
Quote:
Originally Posted by GaryMazzone
I change the database location of Crystal reguarly using VB and Aceess databases. It wis different between verison 8 of Crystal and versions newer then that. If you would like an example let me know and I' post them.
I have been working on this for over two months now and can't figure it out if you could post examples that would be great. I have tried EVERYTHING!!