I am redoing a VB6 application. In the print function the app determines which printer to use, I want to change this to let the OS choose which printer to use is this doable?

7 Years
Discussion Span
Last Post by jaz215

How is the program choosing the printer? What is the method of printing?

If printer.print mystring then
remove/comment out printer selection code
End If


OS will always print to the Default printer.

Debasisdas is absolutely right, as usual.

But I take it when you're saying the app is determining which printer to print, you feel that your user is hemmed in and has no choice of his own to choose which printer?

Good programming always lets the user make his own choice, if possible. In most cases with printing, you're limited to the installed printers on the Windows operating system.

I would use the Printers Collection object in VB6 to find them as follows:

dim prn as Printer, intIndex as Integer
dim iMyPrinters() as integer ' an array of installed printer Indexes
dim strPrinters() as string
intIndex = 0

for each prn in Printers
   debug.print prn.name, intIndex
   Redim Preserve iMyPrinters(intIndex)
   Redim Preserve strPrinters(intIndex)
   iMyPrinters(intIndex)= 0
   strPrinters(intIndex) = prn.Name
   intIndex = intIndex + 1

That code's off the top of my head-- i.e. it may not be accurate. But that should give you a general idea of how you determine what printers are on the system. Once you've decided which printer you want to use through code, then let the user set the printer to the printer of his choice:

Set Printer = intIndex

Of course, you'll have to write code to determine which is the correct index number to use. The printers index ranges from from 0 to Printers.Count-1.


Thanks for the swift reply guys! I'll try out your suggestions and get back to you when I have feedback. Thanks again!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.