Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printing question

Posted on 2002-04-19
7
Medium Priority
?
179 Views
Last Modified: 2010-05-02
Hi,

I have a method that prints out a picture, and I am using the Printers collection in the code, along with the Printer object, like so:

frmMain.CommonDialog1.ShowPrinter
frmMain.CommonDialog1.Flags = cdlPDReturnDC
 
Dim Y As Printer
For Each Y In Printers
    If Y.hdc = frmMain.CommonDialog1.hdc Then
        ' Set printer as system default.
        Set Printer = Y
        ' Stop looking for a printer.
        Exit For
    End If
Next

The above works fine. Through this code, I aquire the printer that the user selected from the CommonDialog object. My problem is that now "Printer", which used to point to the default printer, now points to another printer, which has now become the default printer. Is there a way to set the default printer back to what it was before I changed it?

I have already tried the following:

"Dim DefaultPrinter as Printer
 Set DefaultPrinter = Printer

 'lines of code to do all my printing stuff
 Set Printer = DefaultPrinter"

This doesn't seem to work, DefaultPrinter never receives a value. Also tried this at the very begining of the method:

    Dim X As Printer
    For Each X In Printers
        If X.hdc = Printer.hdc Then
            Set DefaultPrinter = X
            Exit For
        End If
    Next
This never finds a match either. I am stumped now. Any help would be appreciated.


0
Comment
Question by:jhamlett
[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
7 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 6955203
Just store the device name.

Then use code a bit like this:


StorePrinter = Printer.DeviceName

' Do your printing


CAll SetPrinter(StorePrinter)

' Etc....


Sub SetPrinter(DeviceName as string)

Dim Pr as Printer
For Each Printer in Printers
    If Ucase(Pr.DeviceName) = Ucase(DeviceName) Then
        Set Printer = Pr
        Exit Sub
    End If
Next

End Sub



0
 
LVL 17

Expert Comment

by:inthedark
ID: 6955204
I expect in your form load/Sub Main you have:

Printer.TrackDefault = True
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
inthedark earned 400 total points
ID: 6955206
Woops...
For Each Pr in Printers

Would work better, so its like:

Sub SetPrinter(DeviceName as string)

Dim Pr as Printer
For Each Pr in Printers
   If Ucase(Pr.DeviceName) = Ucase(DeviceName) Then
       Set Printer = Pr
       Exit Sub
   End If
Next

End Sub
0
 

Author Comment

by:jhamlett
ID: 6963520
Both good answers. I tried intherdark's method, since it was the simplest, and I do get back the default device name. I seem like I am setting the printer i want back to default, until I re-enter the function and re-open the common dialog. at that point, it still shows the last printer selected as being default? Since I am getting the selected printer via the .hDc prop of the common dialog, is it likely that the common dialog is setting the default based on its own .hDc?
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6964178
jhamlett, just an after thought.  When I develop an App. I get the op. to select the printers they want to use for invoices and also for reports.  So I always select the right printer for the job, then return it to the default after the report is complete.

The documentation covering the use is the common dialog in respect of printers is very poor.  The documentation expected you to be using the RTF control.....but why would I want to use that when most be use Word for WP?
0
 

Expert Comment

by:torrid333
ID: 11382521
I tried implementing this and it does not selet the current printer...

Anyone have an updated version of this type of code all in one place????
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

596 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