Pulling in unique items in a drop down box

R

Richard Edwards

The following code pulls in the company names of the people listed in our
contact list.

Obviously we have more than one person for each company, so the list shows
the company name more than once.

Is there a way of filtering and returning one entry person company?

Thank you.

Richard

-----

Function Item_Open()
Dim cmbContacts
Dim cmbView
Dim OVCtl1
Dim IsLoading
Dim RestrictedContactItems
Const olFolderContacts = 10
On Error Resume Next
Set cmbContacts =
Item.GetInspector.ModifiedFormPages("P.2").Controls("cmbContacts")
Set MyContacts =
Application.GetNameSpace("MAPI").GetDefaultFolder(olFolderContacts)
Set MyItems = MyContacts.Items
Set RestrictedContactItems = MyItems.Restrict("[Company] <> ''")
'Sort by Company in ascending order
RestrictedContactItems.Sort "[Company]"
For Each MyItem in RestrictedContactItems
cmbContacts.AddItem MyItem.CompanyName
Next
IsLoading = True
cmbContacts.ListIndex = 0
IsLoading = False
End Function
 
K

Ken Slovak - [MVP - Outlook]

Add the names to a collection as you get them. Use the company name as both
the value and key for the collection item. Any dupes will error out in the
collection's Add method. Just ignore the error and proceed. At the end you
will have a collection of unique names. Iterate the collection to fill your
drop-down.
 

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

Similar Threads


Top