Link to home
Start Free TrialLog in
Avatar of rev0304
rev0304Flag for United States of America

asked on

Print a Report in Landscape with VB.NET using Crystal Reports Viewer

I am using VB.Net 2005 and CR 11.5    Trying to give the user two options, either Preview or Direct Print.  I can get the Preview to work easily by using the .Show() method.  Problem is when I try to bypass the preview mode and send the report instead directly to the printer, it ends up printing any report in Potrait Orientation, even if the report is designed and designated as Landscape.

Currently using the objCRViewer.PrintReport() method, which brings up the printer selection dialog box.  I also tried bringing up my own MS Print Dialog and passing the parameters to the objReport.PrintToPrinter() method, but I keep getting a "Missing Parameters" error, but of course doesn't tell me what is missing.  Please help!
Avatar of Mike McCracken
Mike McCracken

What code are you using?

I have found that reports switch properly between portrait and landscape if the printer defaults to landscape rather than portrait.  Not sure if that was the printer we used or if it is true for all printers.

mlmcc
Avatar of rev0304

ASKER

The code I am running is below, of course in context to the rest of my application.

There are two Print lines, one using the CRViewer [.PrintReport()] and the other using the Report Object [.PrintToPrinter()]... I commented out both lines

Hope this helps.
        '***************************************
        ' Initialize Variables
        '***************************************
        Dim objPrintDialog As New PrintDialog
 
        '***************************************
        ' Default Values
        '***************************************
        With objPrintDialog
            .AllowCurrentPage = False
            .AllowPrintToFile = False
            .AllowSelection = False
            .AllowSomePages = False
            .ShowDialog(Me)
        End With
 
        '***************************************
        ' Attach Data To Report
        '***************************************
        With Me._objReport
            .SetDataSource(Me._objDataSet)
            .Refresh()
        End With
 
        '***************************************
        ' Re-Instantiate Preview Form If Needed
        '***************************************
        If IsNothing(Me._objCRPreviewForm) OrElse Me._objCRPreviewForm.IsDisposed Then
            Me._objCRPreviewForm = New frmCrystalPreview
        End If
 
        '***************************************
        ' Print Report
        '***************************************
        With Me._objCRPreviewForm
            If Not IsNothing(Me._objParamFields) Then
                .CRViewer.ParameterFieldInfo = Me._objParamFields
            End If
            .CRViewer.ReportSource = Me._objReport
            With Me._objReport
                .PrintOptions.PrinterName = objPrintDialog.PrinterSettings.PrinterName
                '.PrintToPrinter(objPrintDialog.PrinterSettings.Copies, objPrintDialog.PrinterSettings.Collate, 0, 0)
            End With
            Me.Message_Close()
            '.CRViewer.PrintReport()
            .Dispose()
        End With

Open in new window

Does your report require parameters?

mlmcc
Avatar of rev0304

ASKER

Some do, not all of them.
The REFRESH drops the parameters.  Try deleting that line

mlmcc
Avatar of rev0304

ASKER

I think you misunderstood, the parameters missing error I am getting is a VB IDE error regarding the PrintToPrinter() method, it is not a Crystal Error regarding report parameters. I am aware that .Refresh() drops parameters, which is why, if you noticed, I use the .Refresh() before I apply the parameters so that way I do not lose them.  But all in all, the Parameters are not my problem, they work perfectly fine.  My problem is being able to print in Landscape.
It may be the nested WITH structure.  Try fully qualifying the PrintToPrinter.

mlmcc
Avatar of rev0304

ASKER

Nope, that didn't fix it.  :-(
Is the printer dialog displayed or open?

mlmcc
Avatar of rev0304

ASKER

Yes the Printer Dialog displays perfectly fine.
Is it still open when you try to reference it?

mlmcc
Avatar of rev0304

ASKER

If you are asking if I disposed the object, no.  The code above shows you that.  But it's a moot point, because the problem of not being able to directly print in Landscape happens using the PrintReport() method also, which uses it's own PrintDialog box.  The problem I am having ultimately is not a coding problem, but rather I think it's a Crystal problem.  Either Crystal has a bug, or there is an additional setting that I am unaware of to get it to print the way it should.
No, since you are pulling information from the Printer Dialog, it must be open to use the information.  Generally once displayed to get off of it you click OK and it closes.

I have found that to get reports to print in landscape, the printer must be set to landscape as default.
For some reason reports switch to portrait with no problem but switching to landscape doesn't seem to work.

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of rev0304
rev0304
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial