Results 1 to 4 of 4
  1. #1
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150

    How to detect items selected in a list box

    How do I retrieve all the items selected from a list box? Note, there may be more than one item selected.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You have to loop through the items.

    Snippet of code from http://www.allenbrowne.com/ser-50.html
    Code:
    <snip>
        'Loop through the ItemsSelected in the list box.    
        With Me.lstCategory   '<--listbox name
            For Each varItem In .ItemsSelected
                If Not IsNull(varItem) Then
                    'Build up the filter from the bound column (hidden).
                    strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & ","
                    'Build up the description from the text in the visible column. See note 2.
                    strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
                End If
            Next
        End With
    <snip>

  3. #3
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    Thanks, Steve. I'm not an expert, so I don't fully understand the parts that is doing the concatenation. I basically would like to pass the selected values from the list box to a query parameter. I'll pass it using TempVar or function. So, I have a list box with four choices, "Open, to be verified, canceled, completed". If the user chooses "canceled" and "completed", I need to pass the string to the parameter as
    "canceled" or "completed"
    . How do I achieve that?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You have a multi-select listbox so you have to loop through the ItemsSelected collection of the list box to generate a string of the selected items.

    The snippet of code shows how to loop through the listbox to get the selected items.

    This is the best I can do - I know nothing about your dB.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-27-2016, 12:07 PM
  2. Replies: 1
    Last Post: 03-05-2013, 06:53 PM
  3. Replies: 3
    Last Post: 10-23-2012, 03:32 PM
  4. List Box Items Are De-Selected On A Screen Refresh
    By plengeb in forum Programming
    Replies: 2
    Last Post: 10-03-2012, 11:58 AM
  5. Replies: 5
    Last Post: 04-04-2011, 09:57 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