Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Location
    Ohio, United States
    Posts
    167

    Unanswered: Populating list box's row source with printer names

    I would like a form to populate a list box's row source with all available printer names on the form's open event. I found the following Public Function but I'm not sure how to call it in my form (also not sure if code is VBA or VB). Can someone point me in the right direction? Thanks!

    Code:
    Public Function PopulateListControlWithPrinters(ListControl As _
    Object) As Boolean
    
    On Error GoTo errHandler:
    Dim l As Long
    Dim lCount As Long
    ListControl.Clear
    
    lCount = Printers.Count
    
    If lCount = 0 Then
        ListControl.AddItem "(No Printer Installed)"
    Else
        For l = 0 To lCount - 1
            ListControl.AddItem Printers(l).DeviceName
        Next
    End If
    
    PopulateListControlWithPrinters = True
    
    Exit Function
    errHandler:
    PopulateListControlWithPrinters = False
    Exit Function
    
    End Function

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    Put that code in a public module (create one if you don't already have one you can put this in). On the form's open event, do something like:
    Code:
    Dim blnPopulated as boolean
    
    blnPopulated = PopulateListControlWithPrinters(Forms!frmName!ctlName)
    
    if not blnPopulated then
        Msgbox "Printer List Error",vbokonly + vbexclamation,"You have failed.  F--"
    End If
    Obviously you'll have to substitute your form's name and your control's name where I've bolded in the code.

    Cheers!
    Me.Geek = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •