Results 1 to 5 of 5

Thread: [RESOLVED] Print to selected printer

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] Print to selected printer

    I am trying to select the printer from a listbox and printform.
    the code:

    Code:
    Sub LoadPrinters()
        Dim i As Integer
        Dim lCount As Long
        Dim p As Printer
        lCount = Printers.Count
          If lCount = 0 Then
            Call MsgBox("No printer detected on this system", vbExclamation, App.Title)
          End If
           
            For Each p In Printers
             lstPrinters.AddItem p.DeviceName
            Next        
        
        Exit Sub 
    ErrHandler:
    End Sub
    How do i set the print to the listbox selected printer ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Print to selected printer

    Wouldn't it be something as simple as: Printers(lstPrinters.ListIndex).hDC ?
    or
    Code:
     Dim p As Printer
    Set p = Printers(lstPrinters.ListIndex)
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Print to selected printer

    No dim a printer, printer is a global device and it is usually identified by its devicename string

    simply :

    set Printer = List1.list(List1.ListIndex)

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Print to selected printer

    Quote Originally Posted by Navion View Post
    No dim a printer, printer is a global device and it is usually identified by its devicename string
    simply :
    set Printer = List1.list(List1.ListIndex)
    True. Printer is a global property/class object. Should the need exist, one can create a separate instance by using the Printers collection

    Though you should get a type mismatch if trying to set it to some cached devicename
    Suggest instead: Set Printer = Printers(List1.ListIndex)
    Last edited by LaVolpe; Oct 11th, 2014 at 11:11 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Print to selected printer

    thanks guys
    Set Printer = Printers(List1.ListIndex)
    this works
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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