Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing datasource at runtime 1

Status
Not open for further replies.
Sep 29, 2003
28
0
0
BY
I've made some reports, they connect to MSSQL Server trough OLEDB/ADO. Reports are viewed from LotusNotes Application. Everything works fine , but when I try to connect to other database (with the same structure) on the same server or on other server report takes data from olddatabase. How can I change report datasource from VBscript (I use CR9, option 'Save data wth report' switched off)? Here's the example of my VBScript:
Sub Postopen(Source As Notesuidocument)
Dim Viewer As Variant
Set Viewer = Source.getObject( "Crystal Report Viewer Control 9" )
Dim App As Variant
Set App = createObject ("CrystalRuntime.Application" )
Dim Rep As Variant
Set Rep = App.openReport( "C:\Temp\aaa.rpt" )
Rep.Database.tables(1).setLogOnInfo SERVER, DatabaseName,username,password
Set Viewer.reportSource = Rep
Viewer.viewReport
End Sub

 
Here is a code sample that works for me. It's in a vb app, so modify what doesn't apply to your environment. It uses the ConnectionProperties collection rather than the SetLogOnInfo method and appears to be the prefered method in CR 9:

Dim crApp As New CRAXDRT.Application
Dim crRpt As CRAXDRT.Report


Private Sub Form_Load()

Dim crTable As CRAXDRT.DatabaseTable
Dim CPProperty As CRAXDRT.ConnectionProperty


Set crRpt = crApp.OpenReport("C:\Appsdata\Crystal\Developer Testing\OLEDB Connection to mftp.rpt")

'This logs onto the database
For Each crTable In crRpt.Database.Tables
Set CPProperty = crTable.ConnectionProperties("Data Source")
CPProperty.Value = "DELL-LAPTOP"
'CPProperty.Value = "INSPIRON8200\INSPIRON_8200"
Set CPProperty = crTable.ConnectionProperties("User ID")
CPProperty.Value = "me"
Set CPProperty = crTable.ConnectionProperties("Password")
CPProperty.Value = "password"
Set CPProperty = crTable.ConnectionProperties("Initial Catalog")
CPProperty.Value = "mftp"
Next


With CRViewer91
.ReportSource = crRpt
.ViewReport
End With


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top