I've got a report that works great in Crystal, but when I run the report in VB, I get a nearly blank report. (see attachments)
There are 3 sub reports in the main report.
Here is the code that I use for the report. I've used similar code before and it's worked before.
Dim CRXReport As CRAXDDRT.Report
Dim CRXDb As CRAXDDRT.Database
Dim CRXTbl As CRAXDDRT.DatabaseTable
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim init As Integer
Dim rptNum As Integer
Dim rptBranch As String
Dim rptDate As String
Set CRXReport = Report
Set CRXDb = CRXReport.Database
Set Report = app.OpenReport("D:\mgmntReport\mgmntReportLandscape.rpt")
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.Open "Driver={SQL Server};Server=TSGDEV07;Database=SEDONADW;Uid=sa;Pwd=psswrd;"
rs.Open "SELECT DISTINCT cono, officeno FROM management_YTD_Payroll", con
rptDate = Trim(Str(Month(Date))) & Trim(Str(Day(Date))) & Trim(Str(Year(Date)))
'MkDir "c:\MgmntReports\" & rptDate & "\"
rptNum = 1
Do While Not (rs.EOF Or rs.BOF)
Report.DiscardSavedData
frmMain.Show
'Debug.Print Report.Database.Tables.Count
Report.Database.Tables.Item(1).SetLogOnInfo "TSGDEV07", "sedonaDW", "sa", "psswrd"
Report.Database.Tables.Item(2).SetLogOnInfo "TSGDEV07", "sedonaDW", "sa", "psswrd"
Report.Database.Tables.Item(3).SetLogOnInfo "TSGDEV07", "sedonaDW", "sa", "psswrd"
Report.Database.Tables.Item(4).SetLogOnInfo "TSGDEV07", "sedonaDW", "sa", "psswrd"
Report.ParameterFields(1).AddCurrentValue Str(rs.Fields("cono"))
Report.ParameterFields(2).AddCurrentValue Str(rs.Fields("officeno"))
Report.ExportOptions.DestinationType = crEDTDiskFile
Report.ExportOptions.FormatType = crEFTPortableDocFormat
Report.ExportOptions.PDFExportAllPages = True
Report.ExportOptions.DiskFileName = "D:\mgmntReport\Reports\" & rs.Fields("cono") & rs.Fields("officeno") & ".pdf"
Report.Export False
rs.MoveNext
Loop
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
Set CRXReport = Nothing
Anyone have any suggestions?I think the problem may be with the sub-reports.
The 'Report.Database.Tables.Item(1).SetLogOnInfo ...' lines are only setting the logOnInfo for the tables in the main report. I need to login to about 6 other tables for the sub reports. I have no idea about how to do that though.|||I have an idea how to get to the sub report.
Report.OpenSubreport("billings.rpt").Database.Tables.Item(1).SetLogOnInfo..."
also
report.OpenSubreport("billings.rpt").ParameterFields(1).addCurrentValue..."|||Here is what i got to work. (adapted from http://support.businessobjects.com/communitycs/filesandupdates/scr8_vb_rdc_subreports.exe.asp)
Option Explicit
'this application illustrates how to set properties of a subreport at runtime
'although it specifically sets the database location and the value for a text object
'the logic is the same for formatting fields, passing log on information, setting parameter values, etc.
Dim app As New CRAXDDRT.Application
Dim Report As New CRAXDDRT.Report
'Dim CRReport As New CrystalReport1
Private Sub Form_Load()
Dim CRXReport As CRAXDDRT.Report
Dim CRXDb As CRAXDDRT.Database
Dim CRXTbl As CRAXDDRT.DatabaseTable
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer
Dim x As Integer
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.Open "Driver={SQL Server};Server=TSGDEV07;Database=SEDONADW;Uid=sa;Pwd=psswrd;"
rs.Open "SELECT DISTINCT cono, officeno FROM management_YTD_Payroll", con
Set CRXReport = Report
Set CRXDb = CRXReport.Database
Set Report = app.OpenReport(rptPath & "mgmntReportLandscape.rpt")
'this code works through the RDC object model to identify a subreport object
'in the main report
Dim crSecs As CRAXDRT.Sections
Dim crSec As CRAXDRT.Section
Dim crRepObjs As CRAXDRT.ReportObjects
Dim crSubRepObj As CRAXDRT.SubreportObject
Dim crSubReport As CRAXDRT.Report
Set crSecs = Report.Sections
For i = 1 To crSecs.Count
Set crSec = crSecs.Item(i)
Set crRepObjs = crSec.ReportObjects
For x = 1 To crRepObjs.Count
If crRepObjs.Item(x).Kind = crSubreportObject Then
Set crSubReport = Report.OpenSubreport(crRepObjs.Item(x).SubreportName)
'the following code sets the subreport table to a different database
For j = 1 To crSubReport.Database.Tables.Count
crSubReport.Database.Tables.Item(j).SetLogOnInfo "TSGDEV07", "sedonaDW", "sa", "psswrd"
Next j
'within this loop you can set other properties of the subreport and
'the field objects and sections in it.
End If
Next
Next
Do While Not (rs.EOF Or rs.BOF)
Report.DiscardSavedData
Report.ParameterFields(1).AddCurrentValue CStr(rs.Fields("cono"))
Report.ParameterFields(2).AddCurrentValue CStr(rs.Fields("officeno"))
Report.ExportOptions.DestinationType = crEDTDiskFile
Report.ExportOptions.FormatType = crEFTPortableDocFormat
Report.ExportOptions.PDFExportAllPages = True
Report.ExportOptions.DiskFileName = "D:\mgmntReport\Reports\" & rs.Fields("cono") & rs.Fields("officeno") & ".pdf"
Report.Export False
rs.MoveNext
Loop
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
End
End Sub
Private Sub Form_Resize()
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
frmMain.WindowState = vbMaximized
End Sub
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment