Solved

Set printer in reportviewer

Posted on 2008-10-29
5
1,071 Views
Last Modified: 2013-11-26
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?
0
Comment
Question by:Don VonderBurg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:kdwood
ID: 22835744
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.

Regards,

Keith
0
 
LVL 1

Author Comment

by:Don VonderBurg
ID: 22835833
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,

Don
0
 
LVL 10

Accepted Solution

by:
kdwood earned 500 total points
ID: 22841944
Ok, I understand now.  Give this a try:

        Dim strOldPrinter As String
        Dim WshNetwork As Object
        Dim pd As New Printing.PrintDocument
 
        Try
            
            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.SetDefaultPrinter(strOldPrinter)
 
        Finally
 
            WshNetwork = Nothing
            pd = Nothing
 
        End Try

Open in new window

0
 
LVL 10

Expert Comment

by:kdwood
ID: 22841966
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.

Regards,

Keith
0
 
LVL 1

Author Closing Comment

by:Don VonderBurg
ID: 31511349
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".
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question