I am trying to call a Crystal Report (CR10) that has a subreport (the subreport connects to a different database than the main report) through my VB6 program. I usually don't have a problem calling reports with my code, but I've never done a report that has a subreport that connects to a different database (username and password is the same for the second database. The only thing different is the database name).
I found the code below in the FAQ's here, and after changing the server, database name, password, etc to match mine, I still cannot get it to work.
Any help is appreciated!
--------------------------------------
Dim Report As CRAXDRT.Report
Dim SubReport As CRAXDRT.Report
Dim App As CRAXDRT.Application
Dim Sections As CRAXDRT.Sections
Dim Section As CRAXDRT.Section
Dim RepObjs As CRAXDRT.ReportObjects
Dim SubReportObj As CRAXDRT.SubreportObject
Dim n As Integer
Dim i As Integer
Dim j As Integer
Set App = New CRAXDRT.Application
Set Report = App.OpenReport("your.rpt")
For n = 1 To Report.Database.Tables.Count
Report.Database.Tables.SetLogOnInfo "server", "dbname", "user", "pass"
Next n
Set Sections = Report.Sections
For n = 1 To Sections.Count
Set Section = Sections.Item
Set RepObjs = Section.ReportObjects
For i = 1 To RepObjs.Count
If RepObjs.Item(i).Kind = crSubreportObject Then
Set SubReportObj = RepObjs.Item(i)
Set SubReport = SubReportObj.OpenSubreport
For j = 1 To SubReport.Database.Tables.Count
SubReport.Database.Tables(j).SetLogOnInfo "server", "db", "username", "pass"
Next j
End If
Next i
Next n
I found the code below in the FAQ's here, and after changing the server, database name, password, etc to match mine, I still cannot get it to work.
Any help is appreciated!
--------------------------------------
Dim Report As CRAXDRT.Report
Dim SubReport As CRAXDRT.Report
Dim App As CRAXDRT.Application
Dim Sections As CRAXDRT.Sections
Dim Section As CRAXDRT.Section
Dim RepObjs As CRAXDRT.ReportObjects
Dim SubReportObj As CRAXDRT.SubreportObject
Dim n As Integer
Dim i As Integer
Dim j As Integer
Set App = New CRAXDRT.Application
Set Report = App.OpenReport("your.rpt")
For n = 1 To Report.Database.Tables.Count
Report.Database.Tables.SetLogOnInfo "server", "dbname", "user", "pass"
Next n
Set Sections = Report.Sections
For n = 1 To Sections.Count
Set Section = Sections.Item
Set RepObjs = Section.ReportObjects
For i = 1 To RepObjs.Count
If RepObjs.Item(i).Kind = crSubreportObject Then
Set SubReportObj = RepObjs.Item(i)
Set SubReport = SubReportObj.OpenSubreport
For j = 1 To SubReport.Database.Tables.Count
SubReport.Database.Tables(j).SetLogOnInfo "server", "db", "username", "pass"
Next j
End If
Next i
Next n