How to select from Multiple printers
I am using VB6
I have an LX300 printer connected to LPT1 and a cannon inkjet plugged into USb
How can I with code in my program route certain print jobs to the LX300 and others to the cannon without having to prompt the user to choose a printer (using print dialogue box)
Re: How to select from Multiple printers
First find the count of the particular printer using something like this:
Code:
For i = 1 to Printers.Count - 1
printername= Printers(i).Name
if printername = "LX300" then
printernumber=i
exit for
end if
Next i
Then in the place of Printer. use Printer(printernumber).
eg: Instead of
Printer.print "Hello"
use
Printer(printernumber).print "Hello"
Hope this gives you an idea how to proceed.
Re: How to select from Multiple printers
Many Thanks
I will give it a try
Re: How to select from Multiple printers
I get an error Message
'Object does not support this property or method'
Re: How to select from Multiple printers
Re: How to select from Multiple printers
Hi Hack
On This Line
printername= Printers(i).Name
Re: How to select from Multiple printers
I figured it had to be one of the printername lines.
Try Printer.DeviceName instead.
Re: How to select from Multiple printers
Thanks I will try that
I am not on my own machine at the moment but will try it as soon as i can
Re: How to select from Multiple printers
There is no such thing as "printername" (unless someone is using it as a variable and didn't post that part of the code.)
Re: How to select from Multiple printers
probably the best way is to change the printer for your application as this gives the ability to change any properties for the printer prior to prnting
Quote:
Dim X As Printer
For Each X In Printers
If X.Orientation = vbPRORPortrait Then
' Set printer as system default.
Set Printer = X
' Stop looking for a printer.
Exit For
End If
Next
just change the printer each time to print to the correct printer
note you can also change the printer using the commondialog showprinter method, but this also change the default windows printer, which an undesired effect, there is also a printer dialog dll from microsoft that works better, the instruction and download can be obtained from http://support.microsoft.com/kb/322710/EN-US/#7
Re: How to select from Multiple printers
Sorry, Pls change my code as this:
Code:
dim printername as string
For i = 0 To Printers.Count - 1
printername = Printers(i).DeviceName
If printername = "LX300" Then ' In the place of LX300 enter the name of the printer you want
printernumber = i
Exit For
End If
Next i
Re: How to select from Multiple printers
Thanks Hack, Thanks Guys The first part now works and I have now established that the printer that I want to print to is #2
But when I try this:
Printer(2).Print ‘Hello’
I get the same error message on the above line ‘Object does not support this property or method’
I have tried Printers(2).Print ‘Hello’ but I still get the same error.
What am I missing here?
Re: How to select from Multiple printers
The above code I have got from
http://www.freevbcode.com/ShowCode.A...#selectprinter
I have not tried it myself.
I am surprised that it does not seem to work.
Re: How to select from Multiple printers
The following seems to work.
Code:
Dim defprinter As Printer
For i = 0 To Printers.Count - 1
If Printers(i).DeviceName = Printer.DeviceName Then
Set defprinter = Printers(i) 'The current default printer
Exit For
End If
Next
Set Printer = Printers(2) ' the new default printer
Printer.Print "Hello"
Printer.EndDoc
Set Printer = Printers(i) ' Revert to the original default printer