Results 1 to 5 of 5
  1. #1
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105

    How to Pass ListBox to Function?


    I am having trouble passing a listbox to a sub or function.

    I can pass a textbox without issue, but a listbox is giving me fits. Does anybody have a basic example?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,712
    How are you passing the textbox? Is the listbox multiselect? If not, it should be no different.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    I can pass a textbox to another sub or function like this below.

    Code:
    Private Sub txtCreditFee_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        HighlightTextBoxOnEnter Me.txtCreditFee
    End Sub
    
    Public Sub HighlightTextBoxOnEnter(txtBx As TextBox)
        txtBx.SelStart = 0
        txtBx.SelLength = Len(txtBx.Text)
    End Sub



    I have 7 listboxes for each day of the week starting with Sunday. When any listbox is clicked, i want to pass a string value to search to HighlightPerson sub. There, I will need to find out what listbox is to be searched for this string, and then select that item from the listbox and move on.

    The listboxes are not multiselect.

    Code:
    Private Sub lstSunday_Click() 'pass name to search
        HighlightPerson Me.lstSunday.Column(0, Me.lstSunday.ListIndex)
    End Sub
    
    Private Sub HighlightPerson(nameToFind As String)
        Dim iDay As Integer
        Dim iShift As Integer
        Dim lstDay As ListBox
    
    
        iDay = 0
        iShift = 0
    
        Do While iDay < 7                   '7 days of week - 0=Sunday, 1=Monday, etc.
            lstDay = ReturnDayList(iDay)    'assign a form control to lstDay
            Do While iShift >= 0
                iShift = iShift - 1         'starts at last index of list and counts down
                If lstDay.Column(0, iShift) = nameToFind Then
                    lstDay.Selected(iShift) = True   'Highlight this index
                    Exit Do                          'find the first instance and exit
                End If
            Loop
        iDay = iDay + 1 'next day
        Loop
    End Sub
    
    Private Function ReturnDayList(i As Integer) As ListBox 'Should return an associated listbox to lstDay based on the integer passed
        Select Case i
            Case 0
                ReturnDayList = Me.lstSunday
            Case 1
                ReturnDayList = Me.lstMonday
            Case 2
                ReturnDayList = Me.lstTuesday
            Case 3
                ReturnDayList = Me.lstWednesday
            Case 4
                ReturnDayList = Me.lstThursday
            Case 5
                ReturnDayList = Me.lstFriday
            Case 6
                ReturnDayList = Me.lstSaturday
        End Select
    End Function
    

    I have this working by not using iDay and just having 7 identical loops for each day in the HighlightPerson() sub and ignoring ReturnDayList() completely.

    This could all be completely pointless but i'm curious.

  4. #4
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    still haven't figured this out, bumping for another look

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,712
    It's not clicking for me what exactly you're trying to do, so hopefully somebody else will jump in.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 02-14-2013, 09:33 PM
  2. Replies: 1
    Last Post: 09-10-2012, 11:21 PM
  3. How can I pass the value from a combo box to listbox
    By robertdbuckley in forum Programming
    Replies: 1
    Last Post: 05-24-2012, 08:43 AM
  4. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  5. pass a variable to the MsgBox function
    By 3dmgirl in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 07:14 AM

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 - Senior Forums