Solved

Default Printer

Posted on 2000-05-04
8
331 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

13 Experts available now in Live!

Get 1:1 Help Now