Determining number of selected items in multiselect list box

A

Adam Ruben

In a VBA routine I'm looping through the contacts in the contact folder and
I want to create a text string comprising the values of an OL2002 contact
form custom listbox (i.e. Listbox selections are line 2, Red, and line 4,
Green, and text string becomes "Red, Green"). I want to do something like:
For K = 0 To objItem.ItemProperties.Item("ActivitiesList").ListCount - 1
If objItem.ItemProperties.Item(arrFields(I)).Selected(K) Then
strValue = strValue & objItem.ItemProperties.Item(arrFields(I)).Value(K)
End If
Next

But I get error:VBA doesn't support this property or method. Similar problem
when I do:
Do Until objItem.ItemProperties.Item(arrFields(I)).Value(K) = Nothing
strValue = strValue & objItem.ItemProperties.Item(arrFields(I)).Value(K)
K=K+1
Loop

How can I do this? It's driving me nuts!
 
S

Sue Mosher [MVP]

You're mixing up properties and controls a bit. objItem.ItemProperties.Item("ActivitiesList") returns an ItemProperty object. ListCount is a property of a list box control. You need to set an object variable that represents the control (see http://www.slipstick.com/dev/propsyntax.htm#unbound) and then check the Selected property for each item:

For i = 0 to (lstbox.ListCount - 1)
If lstbox.Selected(i) Then
intCount = intCount + 1
End If
Next
MsgBox intCount & " items are selected"

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top