Listbox.ItemsSelected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sassy2009
    New Member
    • Oct 2009
    • 15

    Listbox.ItemsSelected

    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.c ount. For example it displays NULL 5 times if i have selected 5 items from the listbox. Please help.....
    Code:
    Dim frm As Form, ctl As Control
     Dim varItm As Variant
    
        Set frm = Forms!Listing
        Set ctl = frm!lstDisplay
        For Each varItm In ctl.ItemsSelected
            Debug.Print ctl.ItemData(varItm)
        Next varItm
    Last edited by NeoPa; Nov 3 '09, 12:15 AM. Reason: Please use the [CODE] tags provided.
  • sassy2009
    New Member
    • Oct 2009
    • 15

    #2
    Thanks Guys i just figured it out. Instead of using ItemData i now used Column(0,VarItm ) and it worked.
    Code:
    Dim frm As Form, ctl As Control
    Dim varItm As Variant
    
    Set frm = Forms!Listing
    Set ctl = frm!lstDisplay
    For Each varItm In ctl.ItemsSelected
      [B][I]Debug.Print ctl.ItemData(varItm)[/I][/B]
    Next varItm
    Last edited by NeoPa; Nov 3 '09, 12:15 AM. Reason: Please use the [CODE] tags provided.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      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.

      Comment

      Working...