Efficiently getting contacts from a public folder

  • Thread starter Thread starter Doug Lowe
  • Start date Start date
D

Doug Lowe

Hi all, I'm working on a Word template macro that will list all of the
contacts from a public contacts folder in a combo-box. I have the code
working, but it takes about 15 seconds to load 1,400 contacts. After getting
the oContacts MAPI folder set to the correct public folder, here's the code
that actually loads the combo box:

For Each oContact In oContacts.Items
Dim sName As String
sName = oContact.LastNameAndFirstName & " ( " & oContact.CompanyName &
")"
Me.cboContacts.AddItem sName
Next

Is there a more efficient way to get these contacts? I'm considering caching
the contacts in a text file or something on each client's computer.

TIA,

--Doug
 
CDO is much more efficient for handling large collections. I've never
heard of specific benchmark figures, but you may want to give it a shot.
Caching is a good option (cache the EntryIDs of the Contacts, rather than
the names), or only loading a subset of a hundred or so.

Eric Legault - B.A, MCP, MCSD, Outlook MVP
 
It probably would be somewhat faster to use the SetColumns method for the
Items collection of that folder.

oContacts.Items.SetColumns "LastNameAndFirstName, CompanyName"

Other than that you could the Message object and its Fields collection to
get the contacts as CDO 1.21 Messages and that would be much quicker.
However, CDO is an optional installation for Outlook 2000 and later so it
might not be installed. Also, accessing a contact, even as a Message, using
CDO will fire the security prompts for secure versions of Outlook.
 
Eric,

We usually use an estimate of an order of magnitude for the speed difference
between CDO and OOM code, but CDO in secure Outlook versions will fire the
prompts when accessing a contact as a Message even before you access any of
the Fields.
 
Hello Doug,
Is there a more efficient way to get these contacts? I'm considering caching
the contacts in a text file or something on each client's computer.

Use MapiTables in connection with Redemption.
This is the fastest way in my opinion.
 
I'm thinking to cache the names as displayed in the combo box and the
EntryID. Then I don't have to access the MAPI folder at all to display the
dialog box. When the user makes a selection I can go to the folder to get
the full contact information. I'll have to figure out a way to determine
when to invalidate the cache & refresh the data from the exchange contacts
list.

I'm looking into some of the other options suggested, especially Redemption.
I'm long on .NET, VB & C# experience but this is my first crack at Outlook
programming and after VB.NET, it's hard to come back to VBA :)

Thanks for all the help everyone, keep it coming!

--Doug
 
Back
Top