Results 1 to 3 of 3
  1. #1
    rwahdan@gmail.com is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2015
    Posts
    28

    Exclamation get the text of the selected items in listbox

    Hi,



    I have a listbox with 15 entries, I want to get the selected items (names and not which row), how can this be done?

    code I have will print out the position of the selected items not the names:

    Code:
    Dim varitem As Variant
    Dim strsearch As String
    
    
    
    
    For Each varitem In List21.ItemsSelected
    
    
    strsearch = strsearch + Me.List21.ItemData(varitem)
    MsgBox strsearch
    
    
    Next varitem

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    This slight modification will give you the names for selected items in the the bound column in the listbox
    I've moved the message box out of the loop and replaced + with & vbCrlf

    Code:
    Sub Command1_Click()
    
    Dim varitem As Variant
    Dim strsearch As String
    
    
    For Each varitem In List21.ItemsSelected
        strsearch = strsearch & vbCrLf & Me.List21.ItemData(varitem)
    Next varitem
    
    
    MsgBox strsearch, vbInformation, "Selected listbox items"
    
    
    End Sub
    That will give you a single message with each item selected on a separate line
    Alternatively use this to print to the Immediate window
    Code:
    Debug.Print strSearch
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If the text data is in another column of the listbox:

    Me.List21.Column(x, varItem)

    where x is the zero-based column number containing it.
    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: 16
    Last Post: 03-31-2020, 10:19 AM
  2. limit number of selected items in listbox
    By rwahdan@gmail.com in forum Access
    Replies: 4
    Last Post: 01-28-2018, 01:35 AM
  3. Replies: 4
    Last Post: 07-26-2016, 02:53 AM
  4. Replies: 2
    Last Post: 03-27-2015, 08:48 AM
  5. Selected items in listbox
    By tomodachi in forum Access
    Replies: 1
    Last Post: 09-09-2010, 01:14 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