Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog ShowPrinter problem

Status
Not open for further replies.
Oct 5, 1999
105
0
0
GB
I want the user to be able to select the printer required so use the ShowPrinter method with PrinterDefault set to False as I don't want to change the default, however my program do not get the device selected.

Simplified code is:

Private Sub Command1_Click()
CommonDialog1.PrinterDefault = False
CommonDialog1.ShowPrinter
Printer.Print "Hello"
Printer.EndDoc
End Sub

The Common Dialog does not seem to reveal the selection anywhere so how can I find what was selected.

I'm using VB6 under XP
 
Mine shows all the printers that are installed.

Try it without the printerdefault line.

I always load and use another instance of Commondialog because it seems to depend on what it was last used for as to what the initial directory is shown Eg. Loading another one cancels this.

I have a Commondialog indexed at 0 on the form that I never use.
My code then is something like

Load Commondialog1(1)
Commondialog1(1).Intidir= (Whatever - if using files)
Commondialog1(1).showprinter etc.

When I have finished with it I say
Unload Commondialog1(1)
 
Using CommonDialog1.PrinterDefault = True works fine if you can live with changes to the system default Printer.

Using CommonDialog1.PrinterDefault = False makes the dialog pretty useless because you cannot retrieve the selected Printer.DeviceName from it.

There are a few approaches to overcome this the first is to build your own dialog with a selection list of Printers created from a loop like;

For each p in printers()
List1.AddItem p.devicename
next

On selection of one of the list items you then do;

for each p in printers()
if p.devicename = List1.List(List.ListIndex) then
set printer = p
exit for
end if
next

To set the required printer (the system default is not changed). There are some variations on this at
Alternatively use a wrapper for the system Print dialog which does allow you to return a Print device name 'ref.
 
Thanks for the help, both of you.

I'll have a go and see what works best.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top