Set printer in reportviewer

I have a windows form with a reportviewer element. I have a drop down populated with the printers installed. I would like the user to select the printer from the dropdown and when they click the print button have the correct printer selected in the print dialog box. Has anyone been able to set the printer this way?
Don VonderBurgPresident/CEOAsked:
Who is Participating?
kdwoodConnect With a Mentor Commented:
Ok, I understand now.  Give this a try:

        Dim strOldPrinter As String
        Dim WshNetwork As Object
        Dim pd As New Printing.PrintDocument
            strOldPrinter = pd.PrinterSettings.PrinterName
            WshNetwork = Microsoft.VisualBasic.CreateObject("WScript.Network")
            WshNetwork.SetDefaultPrinter("Your Printer Name That You Want To Use")
            pd.PrinterSettings.PrinterName = "Your Printer Name That You Want To Use"
        Catch exptd As Exception
            WshNetwork = Nothing
            pd = Nothing
        End Try

Open in new window

Greetings dvon,

Why not use the Print Button that is already a part of the default toolbar of the ReportViewer control?  It already has the functionality that you described and required no extra coding.


Don VonderBurgPresident/CEOAuthor Commented:
Keith thank you for the response and good question.

The report I've created needs to go to a different printer other than the default. Most of my users have a different default printer setup in their windows and they have to select the printer manually each time they print my report. I want to store the printer name for my report and when the user clicks the print button make that printer be the selected printer.

Thank you,

By the way,

You will want to do this prior to clicking the print button.  Maybe on the loading of the form that hosts the printviewer control or whatever event calls your specific report.


Don VonderBurgPresident/CEOAuthor Commented:
Perfect, thank you. The only change I needed was to the line "Dim pd As New Printing.PrintDocument" to "Dim pd As New Drawing.Printing.PrintDocument".
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.