Pulling in unique items in a drop down box

  • Thread starter Thread starter Richard Edwards
  • Start date Start date
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
 
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.
 
Back
Top