Hi, maybe this can help:
Imports CrystalDecision s.CrystalReport s.Engine
Imports CrystalDecision s.Shared
Imports CrystalDecision s.ReportSource
Private crParameterFiel ds As New ParameterFields
Private crReportDocumen t As New ReportDocument
Public Sub InitialiseRepor t(ByVal psReportName As String, ByVal psTitle As
String)
Dim tblCurrent As Table
Dim crSubreportObje ct As SubreportObject
Dim subRepDoc As New ReportDocument
Dim crDatabase As
CrystalDecision s.CrystalReport s.Engine.Databa se
Dim crTables As Tables
Dim crTable As Table
Dim crSection As Section
Dim crSections As Sections
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crLogOnInfo As TableLogOnInfo
Dim crpConnectionIn fo As New
CrystalDecision s.Shared.Connec tionInfo
Dim crpTableLogOnIn fo As New
CrystalDecision s.Shared.TableL ogOnInfo
crReportDocumen t.Load(psReport Name)
CrystalReportVi ewer1.ReportSou rce = crReportDocumen t
'
' change server for main report
'
With crpConnectionIn fo
.ServerName = "yourservername "
.DatabaseName = "yourdataba se"
End With
'if integrated security isn't true
crpConnectionIn fo.UserID = "userid"
crpConnectionIn fo.Password = "password"
For Each tblCurrent In crReportDocumen t.Database.Tabl es
crpTableLogOnIn fo = tblCurrent.LogO nInfo
crpTableLogOnIn fo.ConnectionIn fo = crpConnectionIn fo
tblCurrent.Appl yLogOnInfo(crpT ableLogOnInfo)
Next
'Set the sections collection with report sections
crSections = crReportDocumen t.ReportDefinit ion.Sections
For Each crSection In crSections
crReportObjects = crSection.Repor tObjects
For Each crReportObject In crReportObjects
If crReportObject. Kind =
ReportObjectKin d.SubreportObje ct Then
'If you find a subreport, typecast the reportobject
to a subreport object
crSubreportObje ct = CType(crReportO bject,
SubreportObject )
'Open the subreport
subRepDoc =
crSubreportObje ct.OpenSubrepor t(crSubreportOb ject.SubreportN ame)
crDatabase = subRepDoc.Datab ase
crTables = crDatabase.Tabl es
'Loop through each table and set the connection info
'Pass the connection info to the logoninfo object
then apply the
'logoninfo to the subreport
For Each crTable In crTables
With crpConnectionIn fo
.ServerName =
FalProjectFunct ies.OphalenConf igWaarde("Cryst alReport", "Servernaam ")
.DatabaseName =
FalProjectFunct ies.OphalenConf igWaarde("Cryst alReport", "Database")
End With
crLogOnInfo = crTable.LogOnIn fo
crLogOnInfo.Con nectionInfo = crpConnectionIn fo
crTable.ApplyLo gOnInfo(crLogOn Info)
Next
End If
Next
Next
End Sub
Hth greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Agnes" <ag***@dynamict ech.com.hk> schreef in bericht
news:#B******** ******@tk2msftn gp13.phx.gbl...
Please help, i had completed over 30-50 reports, now. our client insist to
change the database name.
anyshorcut that I can change the database name in the report without
re-write all of them ??
Thanks in advance