Select printer tray for Crystal Report

I am using the following vb.net code to print a crystal report (VS2008) and select the printer tray.  No matter what paper source option I select, it always prints from the default tray.  

       Dim cr As New ReportDocument
        cr.Load(sReportPath)
        cr.SetParameterValue("PO", "DP000238690")
        cr.PrintOptions.PaperSource = PaperSource.EnvManual
        cr.PrintToPrinter(1, True, 1, 1)
DeniseData AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike McCrackenSenior ConsultantCommented:
Was the report built with that printer as the default?

Was the report built as an envelope?

mlmcc
DeniseData AnalystAuthor Commented:
I'm using the default printer.

The report is not an envelope .... I tried every possible option to change trays.  That just happened to be the last option I tried when I copied and pasted my code.  No matter what I select, it always prints to the default tray.

cr.PrintOptions.PaperSource = PaperSource.Lower
        cr.PrintToPrinter(1, False, 1, 1)

        cr.PrintOptions.PaperSource = PaperSource.Middle
        cr.PrintToPrinter(1, False, 1, 1)
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

DeniseData AnalystAuthor Commented:
I just tried changing the tray in the printer settings and saving it with the report design.  Why doesn't that work?  No matter what I select, it still prints to the default tray also.
Mike McCrackenSenior ConsultantCommented:
I found on some of my reports that I had to set the printer to default to landscape.  It seems Crystal could change a report back to portrait but it could change it to landscape.

Does the tray have the correct paper in it?
I asked about envelope because you were changing it to envmanual

mlmcc
DeniseData AnalystAuthor Commented:
The printer has the correct paper in it.  I am not printing envelopes ... disregard that ... that was just one of the options that I tried in trying to get it to switch trays.  I tried all options ... PaperSource.Lower, PaperSource.Middle, etc.  All trays are loaded with the correct size paper - letter size.

I changed the printer to default to landscape.  No help.
Mike McCrackenSenior ConsultantCommented:
Don't change to landscape unless you want to print landscape that was just an example of what i had to do.

Perhaps changing the printer to default to the tray you want will work.

mlmcc
Mike McCrackenSenior ConsultantCommented:
Are you using the VS2008 version of Crystal?

You might look at this thread in the Crystal forums
http://forums.sdn.sap.com/thread.jspa?threadID=1837625

mlmcc
Mike McCrackenSenior ConsultantCommented:
Another link from the Crystal forum
http://forums.sdn.sap.com/thread.jspa?threadID=1622136

mlmcc
DeniseData AnalystAuthor Commented:
If I change the printer to default to the correct tray, it works, but then everything else prints to that tray.  I have 2 reports that I need to print from different trays, so I need to change it programmatically or  save it in the report design.

I am using VS2008 version of Crystal.  I'll take a look at the links.
Mike McCrackenSenior ConsultantCommented:
It is a problem that has been an issue with Crystal for some time

mlmcc

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DeniseData AnalystAuthor Commented:
The links were no help.

"It is a problem that has been an issue with Crystal for some time"
         Neither was that :(
Mike McCrackenSenior ConsultantCommented:
I know that wasn't much help but it may explain why it does work.  Part of the problem is how the printers set the tray and when it gets done.

I wonder if you can get the application to set the default printer tray based on the report that is being run.

mlmcc
DeniseData AnalystAuthor Commented:
How so?  Isn't that what I'm already trying to do here:

Dim cr As New ReportDocument
        cr.Load(sReportPath)
        cr.SetParameterValue("PO", "DP000238690")
        cr.PrintOptions.PaperSource = PaperSource.Lower
        cr.PrintToPrinter(1, True, 1, 1)
Mike McCrackenSenior ConsultantCommented:
No, you are changing the printer tray for the report.  I mean the actual printer so that anything that prints will then go to that tray.

I don't know the printer codes so may need to get some other expert in.

mlmcc
DeniseData AnalystAuthor Commented:
Ok, I found this code that is supposed to change the default printer tray, but I can't get it to work.  Maybe I need to post a new question.
-----------------
        Dim Printdoc As New Printing.PrintDocument
        Dim SetPage As New System.Drawing.Printing.PageSettings

        With SetPage
            .PaperSource = Printdoc.PrinterSettings.PaperSources(0)
        End With
        Printdoc.DefaultPageSettings = SetPage
Mike McCrackenSenior ConsultantCommented:
No need for a new question.  I'll try to get a hardware/printer expert
What printer manufacturer?

mlmcc
DeniseData AnalystAuthor Commented:
HP LaserJet 4345 mfp PCL 6

Thanks
byundtMechanical EngineerCommented:
A brute force workaround I have used when printing from Excel is to install more than one instance of a printer. You can then adjust the default settings on the new instance of the printer so that you get the paper tray you need. Then all you need to do programmatically is to choose which printer instance you want to use.
DeniseData AnalystAuthor Commented:
I found this code works in vb6 and crystal 10 for hp printer.

Report.PaperSource = 263     '263 = tray 5 '262 = tray 4 '261 = tray 3 '260 = tray 2
Report.PrintOut False

Why is everything so hard in .net?  I may end up coding this in vb6.

Thanks byundt.  I may try your suggestion first.
Mike McCrackenSenior ConsultantCommented:
I don't think it is .net but rather the API Crystal chose to use.

mlmcc
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.