Connecting Tech Pros Worldwide Help | Site Map

Listbox.ItemsSelected

Newbie
 
Join Date: Oct 2009
Posts: 9
#1: 3 Weeks Ago
Hello All,

I have got a listbox which lists the files from a network folder. I have set the multiselect property to Extended. What iam trying to do now is display the multiple file names from the listbox. The following is the code which i made but instead of returning the selected items value, the code displays NULL n number of times depending on the itemsSelected.count. For example it displays NULL 5 times if i have selected 5 items from the listbox. Please help.....
Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form, ctl As Control
  2.  Dim varItm As Variant
  3.  
  4.     Set frm = Forms!Listing
  5.     Set ctl = frm!lstDisplay
  6.     For Each varItm In ctl.ItemsSelected
  7.         Debug.Print ctl.ItemData(varItm)
  8.     Next varItm
Newbie
 
Join Date: Oct 2009
Posts: 9
#2: 3 Weeks Ago

re: Listbox.ItemsSelected


Thanks Guys i just figured it out. Instead of using ItemData i now used Column(0,VarItm) and it worked.
Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form, ctl As Control
  2. Dim varItm As Variant
  3.  
  4. Set frm = Forms!Listing
  5. Set ctl = frm!lstDisplay
  6. For Each varItm In ctl.ItemsSelected
  7.   Debug.Print ctl.ItemData(varItm)
  8. Next varItm
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#3: 3 Weeks Ago

re: Listbox.ItemsSelected


Sassy,

Thanks for posting the solution. Finding that without any knowledge of what's in your Listbox columns would have been a little complicated ;)

Please remember also, that all code must be posted in [ CODE ] tags on this site.

NB. Although the explanation is correct, the code posted seems to be the original, unchanged, code.
Reply