Page 1 of 1

CRYSTAL REPORT XI print to printer

Posted: Mon Apr 24, 2017 10:13 am
by dutch
Dear All,

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
 

Re: CRYSTAL REPORT XI print to printer

Posted: Mon Apr 24, 2017 10:37 am
by AHF
Dutch,

Just an idea:

Code: Select all

PrinterSetup(),;
oReport:SelectPrinter(PrnGetDrive(),PrnGetName(),PrnGetPort()),;
oReport:PrintOut(.F.)
 
I think "False" must be .F.

Re: CRYSTAL REPORT XI print to printer

Posted: Mon Apr 24, 2017 2:09 pm
by dutch
I've got it.
Thank Antonio,