Solved

Default Printer

Posted on 2000-05-04
8
340 Views
Last Modified: 2010-07-27
Is there a way to get the printer selected in a commondialog without changing the default printer?
0
Comment
Question by:Pennywisdom
[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
8 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2777581
if you list all the printers this way:

Dim X As Printer
For Each X In Printers
   List1.AddItem X.DeviceName
Next

then set it to one of the items in the list:

Set Printer = Printers(List1.ListIndex)


this should set the current printer but not actually change the default printer




0
 

Author Comment

by:Pennywisdom
ID: 2777652
I wanted to use the commondialog because its a standard and as some options already done like the status of the printer
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 2777726
Hi!

Well the Printer in the common dialog is the default Printer.

Printer.DeviceName

returns the selected/current printer

If its empty there is no Printer setup.

This is useful with many reporting tools which use the Printer Device Context to display - Crystal Reports does this.

If you intend your users to display reports its worth checking if there is a default printer to avoid errors!

If you want driver information etc it is available thru the Windows API

Azra Sound is probably right and I like his idea!!

Good Luck

Voodooman!
0
Industry Leaders: 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 9

Expert Comment

by:GivenRandy
ID: 2777969
I have code doing what you say, if you want a sniplet of it.  Anyhow, use the "Printer.hDC".  This is referenced in online help:

With a CommonDialog control, this property returns a device context for the printer selected in the Print dialog box when the cdlReturnDC flag is set or an information context when the cdlReturnIC flag is set.

Note   The value of the hDC property can change while a program is running, so don't store the value in a variable; instead, use the hDC property each time you need it.

The AutoRedraw property can cause the hDC property setting to change. If AutoRedraw is set to True for a form or PictureBox container, hDC acts as a handle to the device context of the persistent graphic (equivalent to the Image property). When AutoRedraw is False, hDC is the actual hDC value of the Form window or the PictureBox container. The hDC property setting may change while the program is running regardless of the AutoRedraw setting.

If the HasDC property is set to False, a new device context will be created by the system and the value of the hDC property will change each time it is called.

0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2777972
Also note that it does not change your default printer (that was our requirement also).
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2777984
Here is portions of the code (parts modified for proprietary reasons), which may help.  This uses a Common Dialog (frmDataFilter.cdMain) and RichTextBox (rtbResults):

On Error Resume Next

With frmDataFilter.cdMain
    .CancelError = True
    .Flags = cdlPDReturnDC + cdlPDHidePrintToFile + cdlPDNoPageNums + cdlPDNoSelection + cdlPDNoWarning
    .ShowPrinter
End With

If (Err.Number <> cdlCancel) Then
    rtbResults.Text = "Some data"
    rtbResults.SelPrint (Printer.hDC
End If

On Error Goto 0
0
 
LVL 9

Accepted Solution

by:
Ruchi earned 100 total points
ID: 2778244
TAke a quick look at
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=4003

"“if you dont want the commondialog1.showprinter method to change your default printer. It also gets you out of using comdlg32.ocx. “
0
 

Author Comment

by:Pennywisdom
ID: 2778500
This is exactly what I was looking for Thanks Alot!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

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