For some reason it didn't work. Perhaps I didn't have it placed correctly. I have a lopp through each subreport and if there is a match for a specific subreport name then 'setdatasource'. End of loop I set the viewer's reportsource. I call a routine (setDbLogonForSubreports) to get the login info before the subreport loop. But I am still getting prompted.
Sub
SetDBLogonForSubreports()
Dim crConnectioninfo As ConnectionInfo
crConnectioninfo = New ConnectionInfo
Dim crTableLogOnInfo As TableLogOnInfo
Dim ServerName As String = "xxxxx"
Dim UserID As String = "xxxxxx"
Dim Password As String = "xxxxx"
Dim DatabaseName As String = "xxxxx"
'pass the necessary parameters to the connectionInfo object
With crConnectioninfo
.ServerName = ServerName
.UserID = UserID
.Password = Password
.DatabaseName = DatabaseName
End With
'set up the database and tables objects to refer to the current report
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables
'loop through all the tables and pass in the connection info
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
'Loop through the sections in the main report to find the subreport objects
'then open the subreport and set the datasource to the subreport
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
crSubreportObject = CType(crReportObject, SubreportObject)
'open the subreport object
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
crDatabase = crSubreportDocument.Database
crTables = crDatabase.Tables
'loop through all the tables in the subreport and
'set up the connection info and apply it to the tables
For Each crTable In crTables
'MessageBox.Show(crTable.Name)
With crConnectioninfo
.ServerName = ServerName
.DatabaseName = DatabaseName
.UserID = UserID
.Password = Password
End With
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
End If
Next
Next
End Sub