Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectioninfo As New ConnectionInfo
Dim crTables As Tables
Dim crTable As Table
Dim Environ As String
Dim crReportDocument As New ReportDocument
Dim subReportDocument As New ReportDocument
Dim crSection As Section
Dim crSections As Sections
Dim crReportobject As ReportObject
Dim crReportobjects As ReportObjects
Dim crSubReportobject As SubreportObject
Dim crDatabase As Database
With crConnectioninfo
.ServerName = strServerOrDSNName
.DatabaseName = strDBNameOrPath
.UserID = strUserID
.Password = strPassword
End With
Try
'Loop through each table in the report and set the connection info
crTables = crReportDocument.Database.Tables
For Each crTable In crTables
crtableLogoninfo = crTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectioninfo
crTable.ApplyLogOnInfo(crtableLogoninfo)
Next
Catch ex As Exception
MsgBox("Unable to Log On To report Tables", MsgBoxStyle.Critical)
MsgBox("Loading of " & strReportName & " Cancelled.", MsgBoxStyle.Information)
'MsgBox(ex.ToString)
GoTo StopHere
End Try
Try
' Loop through each section and find report objects
crSections = crReportDocument.ReportDefinition.Sections
For Each crSection In crSections
crReportobjects = crSection.ReportObjects
For Each crReportobject In crReportobjects
If crReportobject.Kind = ReportObjectKind.SubreportObject Then
' If a subreport is found cast as subreportobject
crSubReportobject = CType(crReportobject, SubreportObject)
' Open the sub report
subReportDocument = crSubReportobject.OpenSubreport(crSubReportobject.SubreportName)
crDatabase = subReportDocument.Database
crTables = crDatabase.Tables
' Loop through each table in the sub report and set the connection info
For Each crTable In crTables
crtableLogoninfo = crTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectioninfo
crTable.ApplyLogOnInfo(crtableLogoninfo)
Next
End If
Next
Next
Catch ex As Exception
MsgBox("Unable to Log On To Sub Report Tables")
' MsgBox(ex.ToString)
End Try