Could someone please help.
I too am using vb to create reports in a batch process. I can create the reports and export them in rtf format. but the formatting gets thrown off pretty much. what I'd really like to do is export it or save it as a crystal report. but when i try this in batch mode i only get my template not the data that was loaded into it. this doesnot happen when i export the file as rtf. below is a sample of my code that does the reporting.
' Function - GenerateReport
' This Function Opens Crystal, Populates the Report Template with data then saves the report
Private Function GenerateReport(lstrAcctName As String, lstrClientName As String, lstrSavePath As String, lstrCounselorName As String, lstrFeeStmtIndicator As String) As Boolean
Const PROC = "GenerateReport"
Dim lstrCrystalReport As String
Dim lRegInfo As AMTS_AQR_DSL.cRuntimeContext
Dim lngErrNum As Long
Dim strErrSrc As String
Dim strErrDsc As String
Dim lstrReportName As String
Dim i As Integer
Dim X As Integer
On Error GoTo ErrorMsg
Set mCrystalApplication = CreateObject("Crystal.CRPE.Application"
Set lRegInfo = New AMTS_AQR_DSL.cRuntimeContext
lstrCrystalReport = lRegInfo.ReportTemplateSource
Job = PEOpenPrintJob(lstrCrystalReport)
'open the report and populate with data
Set mrptCrystalReport = mCrystalApplication.OpenReport(lstrCrystalReport, crOpenReportByTempCopy)
If mrptCrystalReport.HasSavedData = True Then
mrptCrystalReport.DiscardSavedData
End If
Set mCrystalDB = mrptCrystalReport.Database
Set mCrystalTables = mCrystalDB.Tables
Set mCrystalTable = mCrystalTables.Item(1)
mCrystalTable.SetPrivateData 3, g_rstGetLabelData
'new stuff
Set mrptSections = mrptCrystalReport.Sections
For i = 1 To mrptSections.Count
Set mrptSection = mrptSections.Item(i)
Set mrptReportObjects = mrptSection.ReportObjects
For X = 1 To mrptReportObjects.Count
If mrptReportObjects.Item(X).Kind = crSubreportObject Then
Set mrptSubReport = mrptCrystalReport.OpenSubreport(mrptReportObjects.Item(X).Name)
Set mCrystalDB = mrptSubReport.Database
Set mCrystalTables = mCrystalDB.Tables
Set mCrystalTable = mCrystalTables.Item(1)
Select Case mrptReportObjects.Item(X).Name
Case "PPR.rpt"
mCrystalTable.SetPrivateData 3, g_rstGetPPRData
Case "OneYearIPH.rpt"
mCrystalTable.SetPrivateData 3, g_rstGetIPHData
Case "FMI.rpt"
mCrystalTable.SetPrivateData 3, g_rstGetFMIData
Case "PPA.rpt"
mCrystalTable.SetPrivateData 3, g_rstGetPPAData
Case "PPAAccount.rpt"
mCrystalTable.SetPrivateData 3, g_rstGetPPAAccountData
Case "Standard"
If lstrFeeStmtIndicator = "F" Then
mCrystalTable.SetPrivateData 3, g_rstGetFEEData
End If
End Select
End If
Next
Next
lstrReportName = lstrSavePath & lstrAcctName & "-" & lstrClientName & "-" & lstrCounselorName & ".rpt"
' Job = PEOpenPrintJob(lstrCrystalReport)
ExportDll = "u2fcr.dll"
ExportFormat = crUXFCrystalReportType
' result = crPEExportToDisk(job, lstrReportName & Chr(0), ExportDll & Chr(0), ExportFormat, chkNum.Value, chkDate.Value, txtStrDel.Text & Chr(0), txtFieldDel.Text & Chr(0))
result = crPEExportToDisk(Job, lstrReportName & Chr(0), ExportDll & Chr(0), ExportFormat, 0, 0, "" & Chr(0), "" & Chr(0))
If PEStartPrintJob(Job, True) = 0 Then
'ErrorTrap job
End If
'here is where we set the export options
Set mCrystalOptions = mrptCrystalReport.ExportOptions
mCrystalOptions.DestinationType = crEDTDiskFile
mCrystalOptions.formatType = crEFTCrystalReport
mCrystalOptions.DiskFileName = lstrSavePath & lstrAcctName & "-" & lstrClientName & "-" & lstrCounselorName & ".rtf"
mrptCrystalReport.Preview
mrptCrystalReport.Export (False)
'mrptCrystalReport.Save ("C:\test.rpt"
' 'here is where we set the export options
' Set mCrystalOptions = mrptCrystalReport.ExportOptions
' mCrystalOptions.DestinationType = crEDTDiskFile
' mCrystalOptions.FormatType = crEFTRichText
' mCrystalOptions.DiskFileName = lstrSavePath & lstrAcctName & "-" & lstrClientName & "-" & lstrCounselorName & ".rtf"
' mrptCrystalReport.Preview
' mrptCrystalReport.Export (False)
Exit Function
ErrorMsg:
If Err Then
lngErrNum = Err.Number
strErrSrc = Err.Source
strErrDsc = Err.Description
m_objLog.LogEvent vbLogEventTypeError, COMPONENT, MODULE, PROC, _
strErrSrc & " error " & lngErrNum & ": " & strErrDsc
End If
' On Error GoTo 0
' m_strSummary = "Report Processing failed: " & PROC
' m_objLog.LogEvent vbLogEventTypeError, COMPONENT, MODULE, PROC, m_strSummary
Exit Function
End Function