Kbase P51906: Export Failed for Crystal report
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  1/20/2004 |
|
Status: Unverified
FACT(s) (Environment):
Windows NT 32 Intel/Windows 2000
FACT(s) (Environment):
Progress 9.1D
SYMPTOM(s):
Export Failed
Error encountered when trying to export a report created in crystal report
Using OLE
DEF var iRunId AS INTEGER INIT 260760 NO-UNDO.
DEF var cComments AS CHAR INIT "These are the comments." NO-UNDO.
DEF var cLoginIn AS CHAR NO-UNDO.
DEFINE VARIABLE CRApp as com-handle no-undo.
DEFINE VARIABLE CRRpt as com-handle no-undo.
DEFINE VARIABLE CRParams as com-handle no-undo.
DEFINE VARIABLE CRParFld as com-handle no-undo.
DEFINE VARIABLE cReportName AS CHAR NO-UNDO.
DEFINE VARIABLE cOutputFile AS CHAR NO-UNDO.
DEFINE VARIABLE cResults AS CHAR NO-UNDO.
cReportName = "c:\progress\wrk\enoahapp\reports\PolicyClaimCharts.rpt".
FILE-INFO:FILE-NAME = cReportName.
cResults = FILE-INFO:FULL-PATHNAME.
IF cResults = ? THEN DO:
cReportName = "e:\progress\wrk\enoahapp\reports\PolicyClaimCharts.rpt".
FILE-INFO:FILE-NAME = cReportName.
cResults = FILE-INFO:FULL-PATHNAME.
END.
cOutputFile = SESSION:TEMP-DIRECTORY + "\echart" + STRING(iRunId) + ".pdf".
CREATE "CrystalRuntime.Application" CRApp .
CRRpt = CRApp:OpenReport(cReportName, 1) .
CRRpt:EnableParameterPrompting = False .
CRParams = CRRpt:ParameterFields .
CRParFld = CRParams:Item(1) .
CRParFld:ClearCurrentValueAndRange .
CRParFld:AddCurrentValue(iRunId) .
CRParFld = CRParams:Item(2) .
CRParFld:ClearCurrentValueAndRange .
CRParFld:AddCurrentValue(cComments) .
CRRpt:ExportOptions:DestinationType = 1 . /* Disk/File */
CRRpt:ExportOptions:DiskFileName = cOutputFile .
CRRpt:ExportOptions:FormatType = 31 . /* PDF Format */
CRRpt:Export(FALSE) .
RELEASE OBJECT CRParFld .
RELEASE OBJECT CRParams .
RELEASE OBJECT CRRpt .
RELEASE OBJECT CRApp
CAUSE:
The Logon info for the Report Object was not set. The code needed to set the Logon info for the Report Object using the SetLogonInfo method (of the DatabaseTables object) to create a connection to the database that the report object uses.
FIX:
Following is the corrected code using the SetLogonInfo method to create a connection to the database. The additional three lines are enclosed between long comment lines:
DEF INPUT PARAMETER piRunId AS INTEGER NO-UNDO.
DEF INPUT PARAMETER pcComments AS CHAR NO-UNDO.
DEFINE VARIABLE CRApp as com-handle no-undo.
DEFINE VARIABLE CRRpt as com-handle no-undo.
/***** Following line was added *****************************/
DEFINE VARIABLE CRTable AS COM-HANDLE NO-UNDO.
/***** Above line was added ********************************/
DEFINE VARIABLE CRParams as com-handle no-undo.
DEFINE VARIABLE CRParFld as com-handle no-undo.
DEFINE VARIABLE cReportName AS CHAR NO-UNDO.
DEFINE VARIABLE cOutputFile AS CHAR NO-UNDO.
DEFINE VARIABLE cResults AS CHAR NO-UNDO.
cReportName = "c:\progress\wrk\enoahapp\reports\PolicyClaimCharts.rpt".
FILE-INFO:FILE-NAME = cReportName.
cResults = FILE-INFO:FULL-PATHNAME.
IF cResults = ? THEN DO:
cReportName = "e:\progress\wrk\enoahapp\reports\PolicyClaimCharts.rpt".
FILE-INFO:FILE-NAME = cReportName.
cResults = FILE-INFO:FULL-PATHNAME.
END.
cOutputFile = SESSION:TEMP-DIRECTORY + "\echart" + STRING(piRunId) + ".pdf".
CREATE "CrystalRuntime.Application" CRApp .
CRRpt = CRApp:OpenReport(cReportName, 1) .
/***** Following 2 lines were added ***************************/
CRTable = CRRpt:DATABASE:Tables:ITEM(1).
CRTable:SetLogOnInfo("printdb", "", "crystal", "crystal").
/***** Above 2 lines were added *******************************/
CRRpt:EnableParameterPrompting = False .
CRParams = CRRpt:ParameterFields .
CRParFld = CRParams:Item(1) .
CRParFld:ClearCurrentValueAndRange .
CRParFld:AddCurrentValue(piRunId) .
CRParFld = CRParams:Item(2) .
CRParFld:ClearCurrentValueAndRange .
CRParFld:AddCurrentValue(pcComments) .
CRRpt:ExportOptions:DestinationType = 1 . /* Disk/File */
CRRpt:ExportOptions:DiskFileName = cOutputFile .
CRRpt:PaperOrientation = 2 . /* Landscape */
CRRpt:ExportOptions:FormatType = 31 . /* PDF Format */
CRRpt:Export(FALSE) .
RELEASE OBJECT CRParFld.
RELEASE OBJECT CRParams .
RELEASE OBJECT CRTable.
RELEASE OBJECT CRRpt .
RELEASE OBJECT CRApp .