By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,673 Members | 1,696 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Retrieve Values from a Multi-Select ListBox

MMcCarthy
Expert Mod 10K+
P: 14,534
This is an example of code that uses a multi-select ListBox control. This is an area that seems to cause confusion and difficulty for many of our members.
Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.     For Each valSelect In Me.listboxName.ItemsSelected
  5.         strValue = strValue & "'" & Me.listboxName.ItemData(valSelect) & "', "
  6.     Next valSelect
  7.  
  8.     ' to remove trailing comma
  9.     strValue = Left(strValue, Len(strValue)-2)
Jan 18 '07 #1
Share this Article
Share on Google+
1 Comment


TheSmileyCoder
Expert Mod 100+
P: 2,321
I just wanted to expand on this, and show how to get the value of a secondary column in a multiselect listbox:
Expand|Select|Wrap|Line Numbers
  1.    Dim v As Variant
  2.    For Each v In Me.ListBoxControl.ItemsSelected
  3.       Debug.Print Me.ListBoxControl.ItemData(v) & " - " & Me.ListBoxControl.Column(1, v)
  4.    Next
Where 1 is used to indicate I want the second column (Since the column count is 0 based)
Feb 3 '16 #2