Results 1 to 14 of 14

Thread: How to select from Multiple printers

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    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)

  2. #2
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: How to select from Multiple printers

    Many Thanks

    I will give it a try

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: How to select from Multiple printers

    I get an error Message
    'Object does not support this property or method'

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to select from Multiple printers

    On what line?

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: How to select from Multiple printers

    Hi Hack
    On This Line
    printername= Printers(i).Name

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to select from Multiple printers

    I figured it had to be one of the printername lines.

    Try Printer.DeviceName instead.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    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

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.)

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  11. #11
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    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

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    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?

  13. #13
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    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.

  14. #14
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    Kerala, India
    Posts
    275

    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
  •  



Click Here to Expand Forum to Full Width