Getting ListBox values

  • Thread starter Thread starter Alexander V. Alexeev
  • Start date Start date
A

Alexander V. Alexeev

Hi all!

I have been playing around with a listbox which, for instance, has Pear,
Apple, Peach, Melon as values... what I was looking for is a way to retrieve
values that were selected (it's a multi-selection box). The online VBA
reference suggests I do FOR NEXT loop based on ListCount property and test
with IF whether an item with such and such an index was selected... this is
however is not good for my purposes. What if I wanted to really be able to
retrieve it like in HTML <select>... i.e. comma separated or an array of
values... so if one selects Pear and Melon.. it'd show those. I tried using
Value property but it does not seem to show anything.

Ultimately, I plan to have names from Active Directory in the list box and
would need to retrieve their usernames.

Am I missing something, is tehre perhaps a property that does what I
described?

Thanks!
Alex A
 
Alexander,

where´s the problem to build an HTML or comma separated string by
yourself once you´ve gotten the selected items from the list?
 
Well, the thing is that I'd like the values to be retrievable i.e. Melon,
etc from my example, and not in the way the documentation suggests which
gives me only that Item(i) = True or False. Because this way I have no way
of knowing what is actually in the Value. listBox.Value shows nothing and I
am confused by that - how are we supposed to get the values selected...

Thanks,
Alex A
 
Do you talk about the MSForms.Listbox? There´s no Item, but a List
property. List(0,0) returns the first value (row 0 and column 0).
 
PMJI, but value shows nothing because it's a multi-select list box. To get the selected values, you have to iterate the rows and check the Selected property for each one. I think you've already done this, right?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Alexander Alexeev said:
Well, the thing is that I'd like the values to be retrievable i.e. Melon,
etc from my example, and not in the way the documentation suggests which
gives me only that Item(i) = True or False. Because this way I have no way
of knowing what is actually in the Value. listBox.Value shows nothing and I
am confused by that - how are we supposed to get the values selected...

Thanks,
Alex A
 
Yep, and as Michael Bauer suggested in the above post, used the List(0,0)
approach to retrieve the textual value. Thank you both for help with this!

Regards
Alex A
 
Alexander said:
Yep, and as Michael Bauer suggested in the above post, used the List(0,0)
approach to retrieve the textual value. Thank you both for help with this!

Regards
Alex A
Hi Alexander,

did you consider to create a field of type 'keywords' and bind it to
your listbox?
This will deliver some of your functionality without further coding.
It works just like the 'Categories' field if bound to text box, but can
deal with listbox automatically.

Wolfram
 
Back
Top