|
-
Mar 10th, 2008, 04:34 AM
#1
Thread Starter
Fanatic Member
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)
-
Mar 10th, 2008, 05:20 AM
#2
Hyperactive Member
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.
-
Mar 10th, 2008, 06:41 AM
#3
Thread Starter
Fanatic Member
Re: How to select from Multiple printers
Many Thanks
I will give it a try
-
Mar 10th, 2008, 06:49 AM
#4
Thread Starter
Fanatic Member
Re: How to select from Multiple printers
I get an error Message
'Object does not support this property or method'
-
Mar 10th, 2008, 06:51 AM
#5
Re: How to select from Multiple printers
-
Mar 10th, 2008, 07:26 AM
#6
Thread Starter
Fanatic Member
Re: How to select from Multiple printers
Hi Hack
On This Line
printername= Printers(i).Name
-
Mar 10th, 2008, 07:28 AM
#7
Re: How to select from Multiple printers
I figured it had to be one of the printername lines.
Try Printer.DeviceName instead.
-
Mar 10th, 2008, 07:30 AM
#8
Thread Starter
Fanatic Member
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
-
Mar 10th, 2008, 07:33 AM
#9
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.)
-
Mar 10th, 2008, 04:04 PM
#10
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
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 10th, 2008, 08:55 PM
#11
Hyperactive Member
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
-
Mar 11th, 2008, 12:21 AM
#12
Thread Starter
Fanatic Member
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?
-
Mar 11th, 2008, 02:14 AM
#13
Hyperactive Member
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.
-
Mar 11th, 2008, 03:07 AM
#14
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|