Crystal Reports ANd VB 6.0 Printing reports using CRPEAUTO Object, specifying paper orientation problem

Crystal Reports ANd VB 6.0 Printing reports using CRPEAUTO Object, specifying paper orientation problem

Post by KVSGROUP LT » Wed, 01 Sep 1999 04:00:00

Hi There,

I have tried for hours to solve this one.
Using Crystral Reports Pro 6.0 and VB5.0 Enterprise

To print a report to a printer other then the one specified within the
report. I use the CRPEAUTO object for generating and printing reports. I do
not seem to be able to specify the layout of the report ie Landscape or
Portrait. The code is as follows
 This has been trimmed to show just the WORKS ORDER printing.

Even though I set the paper orientation to 2 (landscape) it prints out in
Portrait. But if the printer specified by user is same as one within the
report, the report is printed out in Landscape. the differencc being that
the SelectPrinter method of the Report object does not get called if the
printer selected is the same as the one specified within the report.

appMain object is created with the following statement when the program is
    Set appMain = CreateObject("Crystal.CRPE.Application")

I could get around this by creating reports for each possible type of
Printer and using the relevant report with the selected printer but this to
me seems to be rather longwinded and untidy,not to mention,a nightmare to

Thanks for your time and help in advance, any help or ideas will be
appreciated as I am stumped for the moment.


Function PrintReport(sMode As String, iID As Long, bShowPS As Boolean, iDest
As Integer)

    Dim rptCur As CRPEAuto.Report
    Dim pgSetup As CRPEAuto.PageSetup
    Dim winOpt As CRPEAuto.PrintWindowOptions
    Dim prnInfo As CRPEAuto.PrinterInfo
    Dim winView As CRPEAuto.View
    On Error Resume Next
    sMode = Trim$(UCase$(sMode))
    If sMode = "WORKS ORDER" Then
        sRepFile = sReportPath & "\BCND1.RPT"
        iIDX = 0
        sSF = "({RPTORDERHDR.ORDERID})=" & Str$(iID)
        iOrient = 2
   Set rptCur = appMain.OpenReport(sRepFile)
   Set pgSetup = rptCur.PageSetup
    With pgSetup
        .PaperSize = crPaperA4
        .PaperOrientation = iOrient
    End With
    rptCur.GroupSelectionFormula = sSF
    Set winOpt = rptCur.PrintWindowOptions
    Set prnInfo = rptCur.PrinterInfo
    If iDest = 0 Then
        With winOpt
            .HasPrintSetupButton = True
            .HasPrintButton = True
            .HasGroupTree = False
            .HasCancelButton = True
            .HasCloseButton = True
            .HasNavigationControls = True
            .HasZoomControl = True
            .HasPrintButton = True
            .HasPrintSetupButton = True
            .HasRefreshButton = True
        End With
        Set winView = rptCur.Preview
        If prnInfo.PrinterName <> arrPrinters(iIDX, 0) Or prnInfo.DriverName
<> arrPrinters(iIDX, 1) Or prnInfo.PortName <> arrPrinters(iIDX, 2) Then
            rptCur.SelectPrinter arrPrinters(iIDX, 1), arrPrinters(iIDX, 0),
arrPrinters(iIDX, 2)
        End If
        rptCur.PrintOut bShowPS
    End If
    If Err Then
        MsgBox "An Error Occurred While Printing " + sMode + " #" +
Str$(iID) + " !" + Chr$(13) _
        + "Error Code :" & Str$(Err), MB_ICONINFORMATION
        Err = 0
        PrintReport = False
        Exit Function
    End If
    PrintReport = True

End Function