I have a report with 2 subreports (history comments & open order comments). I conditionally supress the history subreport if there are open comments using a sharedvar. This works fine in the thick client (CR8.5) and if I manually export to PDF. HOWEVER, if I run it in a VBS batch the history report never exports - the open works fine. I'm not sure if it's a timing issue or an export type problem. Suggestions???
Sharedvar formula:
Main Report:
whileprintingrecords;
Shared NumberVar disComments;
disComments :=0
Open Sub:
whileprintingrecords;
Shared NumberVar disComments;
disComments :=disComments + 1
History Sub (format section - conditionally suppress):
whileprintingrecords;
Shared NumberVar disComments;
disComments >0
The VBS section that runs the report is:
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'START - RTF Export Functions - START
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'Set paths to the export directory & path to the Report Path/Filename
Public Const EXPORT_DIRECTORY = "\MfgRepReports"
Public Const REPORT_PATH = "BookingsDetail_MfgRep.rpt"
Public Function ExportReport(strRepNo,strRepName)
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'
'Purpose: Exporting a Crystal Report to PDF
'
'Output: If the function is successfull the Path to the PDF file
' will be returned. If the export file is not successfull
' nothing will be returned (a blank).
'
'Input: strRepNo: Manufacturer's Rep Number
'
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Dim oApp
Dim oRpt
Dim oParmCollection
Dim oParm
Dim strRptName
Dim strEMSBegDate
strEMSBegDate = cstr(DatePart("yyyy",Date) & (right("00" & (DatePart("m",Date)),2)) & "01")
Dim strEMSEndDate
strEMSEndDate = cstr(DatePart("yyyy",Date) & (right("00" & (DatePart("m",Date)),2)) & (right("00" & (DatePart("d",Date)),2)))
'on error resume next
'Right justify the Vendor Number and Buy from number
strRepNo = right(Space(3) & Trim(strRepNo), 3)
'Create the output file name - "BookingsDetail_RepNo.pdf"
strRptName = "BookingsDetail_" & Trim(strRepNo) & ".pdf"
'Create the Crystal Report (8.5) application object
Set oApp = CreateObject("CrystalRuntime.Application.8.5")
'Create a Report object for openning & exporting the report
Set oRpt = oApp.OpenReport(REPORT_PATH)
oRpt.Database.LogOnServer "P2SODBC.DLL","name", "", "loginid","******"
'Get the Parameter colletion
Set oParmCollection = oRpt.ParameterFields
'Assign the Parameter (Beginning Date) to First Day of Current Month
Set oParm = oParmCollection.Item(1)
oParm.SetCurrentValue(CLng(strEMSBegDate))
'Assign the Parameter (Ending Date) to Today
Set oParm = oParmCollection.Item(2)
oParm.SetCurrentValue(CLng(strEMSEndDate))
'Assign the Parameter (Vendor Number)
Set oParm = oParmCollection.Item(3)
oParm.SetCurrentValue(strRepNo)
Set oParm = Nothing
'Assign the Parameter (Vendor Name)
Set oParm = oParmCollection.Item(4)
oParm.SetCurrentValue(strRepName)
Set oParm = Nothing
'Export the report to RTF
oRpt.ExportOptions.FormatType = 31 '4 '31 'crEFTRichText
oRpt.ExportOptions.DestinationType = 1 'crEDTDiskFile
oRpt.ExportOptions.DiskFileName = EXPORT_DIRECTORY & "\" & strRptName 'Export File Path and Name
oRpt.DisplayProgressDialog = False 'Used to determine if the Progress Dialog should be displayed
oRpt.Export False
'oRpt.PrintReport
'Clean up object variables
Set oParmCollection = Nothing
Set oRpt = Nothing
Set oApp = Nothing
'Check to see if the exported file has been created. If it is
'Successful return the path to the file. If it is not
'Successful then return a blank space to signify failure.
If Dir(EXPORT_DIRECTORY & "\" & strRptName)=false Then
'wscript.echo "Export Bad"
ExportReport = ""
Else
'wscript.echo "Export OK"
ExportReport = EXPORT_DIRECTORY & "\" & strRptName
End If
End Function
Sharedvar formula:
Main Report:
whileprintingrecords;
Shared NumberVar disComments;
disComments :=0
Open Sub:
whileprintingrecords;
Shared NumberVar disComments;
disComments :=disComments + 1
History Sub (format section - conditionally suppress):
whileprintingrecords;
Shared NumberVar disComments;
disComments >0
The VBS section that runs the report is:
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'START - RTF Export Functions - START
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'Set paths to the export directory & path to the Report Path/Filename
Public Const EXPORT_DIRECTORY = "\MfgRepReports"
Public Const REPORT_PATH = "BookingsDetail_MfgRep.rpt"
Public Function ExportReport(strRepNo,strRepName)
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'
'Purpose: Exporting a Crystal Report to PDF
'
'Output: If the function is successfull the Path to the PDF file
' will be returned. If the export file is not successfull
' nothing will be returned (a blank).
'
'Input: strRepNo: Manufacturer's Rep Number
'
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Dim oApp
Dim oRpt
Dim oParmCollection
Dim oParm
Dim strRptName
Dim strEMSBegDate
strEMSBegDate = cstr(DatePart("yyyy",Date) & (right("00" & (DatePart("m",Date)),2)) & "01")
Dim strEMSEndDate
strEMSEndDate = cstr(DatePart("yyyy",Date) & (right("00" & (DatePart("m",Date)),2)) & (right("00" & (DatePart("d",Date)),2)))
'on error resume next
'Right justify the Vendor Number and Buy from number
strRepNo = right(Space(3) & Trim(strRepNo), 3)
'Create the output file name - "BookingsDetail_RepNo.pdf"
strRptName = "BookingsDetail_" & Trim(strRepNo) & ".pdf"
'Create the Crystal Report (8.5) application object
Set oApp = CreateObject("CrystalRuntime.Application.8.5")
'Create a Report object for openning & exporting the report
Set oRpt = oApp.OpenReport(REPORT_PATH)
oRpt.Database.LogOnServer "P2SODBC.DLL","name", "", "loginid","******"
'Get the Parameter colletion
Set oParmCollection = oRpt.ParameterFields
'Assign the Parameter (Beginning Date) to First Day of Current Month
Set oParm = oParmCollection.Item(1)
oParm.SetCurrentValue(CLng(strEMSBegDate))
'Assign the Parameter (Ending Date) to Today
Set oParm = oParmCollection.Item(2)
oParm.SetCurrentValue(CLng(strEMSEndDate))
'Assign the Parameter (Vendor Number)
Set oParm = oParmCollection.Item(3)
oParm.SetCurrentValue(strRepNo)
Set oParm = Nothing
'Assign the Parameter (Vendor Name)
Set oParm = oParmCollection.Item(4)
oParm.SetCurrentValue(strRepName)
Set oParm = Nothing
'Export the report to RTF
oRpt.ExportOptions.FormatType = 31 '4 '31 'crEFTRichText
oRpt.ExportOptions.DestinationType = 1 'crEDTDiskFile
oRpt.ExportOptions.DiskFileName = EXPORT_DIRECTORY & "\" & strRptName 'Export File Path and Name
oRpt.DisplayProgressDialog = False 'Used to determine if the Progress Dialog should be displayed
oRpt.Export False
'oRpt.PrintReport
'Clean up object variables
Set oParmCollection = Nothing
Set oRpt = Nothing
Set oApp = Nothing
'Check to see if the exported file has been created. If it is
'Successful return the path to the file. If it is not
'Successful then return a blank space to signify failure.
If Dir(EXPORT_DIRECTORY & "\" & strRptName)=false Then
'wscript.echo "Export Bad"
ExportReport = ""
Else
'wscript.echo "Export OK"
ExportReport = EXPORT_DIRECTORY & "\" & strRptName
End If
End Function