Solved

Set printer in reportviewer

Posted on 2008-10-29
5
1,072 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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