I try this code for Preview and Export to file, it's work well but print to printer doesn't work and got an error.
oRpt:SelectPrinter( cPrinter ) // Error missing method
oRpt:PrintOut("False",nCopy) // Error missing method
Thanks in advance for any help or suggestion.
Code: Select all
*----------------------------------------------------------------------------------*
Procedure CRReport(nOpt, cReport, filter_main, nExport, cTempFile, cPrinter, nCopy)
local oWnd, oCRViewer, oCrystal, oRpt, oExp, oCRParameterField, oRptOut
cReport := MEMVAR->cCRPath+cReport // "C:\Users\dutch\Desktop\CR11\VatReport.rpt" // Report Name
oCrystal:= CreateObject("CrystalRuntime.Application.11") // Declare CreateObject
oRpt := oCrystal:OpenReport(cReport) // Open Report
oRpt:DiscardSavedData()
oRpt:RecordSelectionFormula( filter_main ) // Query database
oRpt:EnableParameterPrompting("False")
// oRpt:DisplayProgressDialog := 1
DEFINE WINDOW oWnd FROM 3, 6 TO 20, 70 ;
TITLE "Print and Preview"
if nOpt = 1 // Print to Printer
oRpt:SelectPrinter( cPrinter ) // Error missing method
oRpt:PrintOut("False",nCopy) // Error missing method
elseif nOpt = 2 // Preview
oCRViewer := TActiveX():New( oWnd, "CrystalReports.ActivexReportViewer" )
oWnd:oClient := oCRViewer
oCRViewer:EnableExportButton := 0
oCRViewer:EnableStopButton:= 1
oCRViewer:EnableNavigationControls:=1
oCRViewer:EnablePopupMenu:=0
oCRViewer:EnableCloseButton:=0
oCRViewer:DisplayGroupTree:=1
oCRViewer:EnableDrillDown:=1
oCRViewer:EnableGroupTree:=1
oCRViewer:EnableStopButton:= 0
oCRViewer:EnablePrintButton := iif( nOpt=2,0,1)
oCRViewer:ReportSource:= oRpt
oCrViewer:Zoom:=100
if nOpt = 1
oCRViewer:PrintReport()
else
oCRViewer:ViewReport()
end
elseif nOpt = 3 // Export
oExp := oRpt:ExportOptions
oExp:DestinationType := 1
oExp:ExcelShowGridLines := 0 // 1
oExp:FormatType := nExport // 36 = Full Excel
oExp:DiskFileName := cTempFile // "D:\TESTCR27.XLS"
oRpt:Export(.F.) // Parameter .T./.F. = oExp:PromptForExportOptions()
oWnd:End()
end
ACTIVATE WINDOW oWnd MAXIMIZED;
VALID (oRpt:CancelPrinting(),oCrystal:CanClose(),oRpt := nil ,.t.)
return