Results 1 to 3 of 3
  1. #1
    JosmithTwo is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    19

    passing the name of a control to a subroutine


    I have a subroutine that process a list box putting its selected items into an array. I have 3 more identical list boxes that need the same process but to different arrays. Can I pass the subroutine the list box and its array name to the subroutine for processing?

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    I use a public function which I assign to a variable
    Just use a different variable for each listbox.

    x = getLbx(me.MyListbox)

    Code:
    Public Function getLBX(lbx As ListBox, Optional intColumn As Variant = 0, Optional Seperator As String = ",", _
                           Optional delim As Variant = Null) As String
    
    
    'Iterates thru the multiselect listbox and constructs an array of the selected items
    'Arguments:
    'Lbx is Listbox Object ie.Me.MyListbox
    'intColumn is the column # to be returned
    'Seperator is the character seperating items in array returned
    'Delim is optional delimiter to be return in array ie. #1/1/2001#,#12/25/2015#
    
    
        Dim strlist As String
        Dim varSelected As Variant
    
    
        'On Error GoTo getLBX_Error
    
    
        If lbx.ItemsSelected.Count = 0 Then
            'MsgBox "Nothing selected"
        Else
    
    
            For Each varSelected In lbx.ItemsSelected
    
    
                If Nz(lbx.Column(intColumn, (varSelected)), "") <> "" Then
    
    
                    strlist = strlist & delim & lbx.Column(intColumn, (varSelected)) & delim & Seperator
    
    
                Else
    
    
                    strlist = strlist
    
    
                End If
    
    
            Next varSelected
    
    
            If Nz(strlist, "") <> "" Then
    
    
                strlist = Left$(strlist, Len(strlist) - 1)  'remove trailing comma
    
    
            End If
        End If
    
    
        getLBX = strlist
    
    
        On Error GoTo 0
        Exit Function
    
    
    getLBX_Error:
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getLBX of Module modLBX"
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    JosmithTwo is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2012
    Posts
    19
    Thanks! just what I needed

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing a string from one subroutine to another
    By catluvr in forum Programming
    Replies: 4
    Last Post: 08-01-2018, 03:16 PM
  2. Passing a control to a sub
    By GraeagleBill in forum Programming
    Replies: 11
    Last Post: 01-19-2018, 02:16 PM
  3. passing a control name as as variable
    By newbieX in forum Programming
    Replies: 3
    Last Post: 09-26-2014, 02:06 PM
  4. Calling Access VBA subroutine from an Excel VBA subroutine
    By richard_yolland in forum Programming
    Replies: 0
    Last Post: 02-16-2011, 11:30 AM
  5. Passing a form name to a subroutine
    By trb5016 in forum Programming
    Replies: 0
    Last Post: 02-01-2010, 12:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums