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!

Subreport Access in VB6

Status
Not open for further replies.

hgraybill

MIS
Mar 30, 2007
32
US
I didn't have any success with posting this in the VB6 subforum, so somebody suggested I post it here.
----------------------------------------
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!

Code:
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(n).SetLogOnInfo "server", "dbname", "user", "pass"
  Next n

  Set Sections = Report.Sections
  For n = 1 To Sections.Count
    Set Section = Sections.Item(n)
    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
 
It's 5 years since I last used CRAXDRT, so apologies if I get this wrong as I use the .Net version now, plus C# rather than VB.

Isn't it possible to just iterate through the subreport collection via the report object, rather than going through all the sections and reportobjects? I think is Report.SubReports or similar.

For debugging what you already have, create a simple report that only contains a few objects and a subreport. Put a breakpoint at If RepObjs.Item(i).Kind, it may not even be picking up the subreports.


Andrew Baines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top