Solved

Default Printer

Posted on 2000-05-04
8
332 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now