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
Solved

Default Printer

Posted on 2000-05-04
8
335 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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…

840 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