?
Solved

Printing question

Posted on 2002-04-19
7
Medium Priority
?
170 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
Technology Partners: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

770 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