Reading Contact Information
Reading basic information from a contact item is just like reading a message. Contact items are represented by Message objects, which reside in Messages collections contained in Folder objects. The code in Example 10-1 shows how to iterate through the contact items found in the user’s Contacts folder.
Example 10-1. Iterating Contacts
' gCdoSession previously Dim'ed, Set, and logged on. Dim CdoFolder As MAPI.Folder Dim CdoMessages As MAPI.Messages Dim CdoMessage As MAPI.Message ' Get the collection of contact items from the Contacts folder. Set CdoFolder = gCdoSession.GetDefaultFolder(CdoDefaultFolderContacts) Set CdoMessages = CdoFolder.Messages ' Loop for each contact. For Each CdoMessage In CdoMessages ' ' Process the contact item. ' Next CdoMessage ' Cleanup Set CdoMessage = Nothing Set CdoMessages = Nothing Set CdoFolder = Nothing
All of the standard Message object
properties can be used with contact items. Note that the Subject
property of the Message object is set to the name of the contact, and
the Type property of the Message object is set to
"IPM.Contact
“.
In addition to the properties exposed by the Message object, standard MAPI contact item-related properties can be accessed through the Message object’s Fields collection.
The process for getting or setting a MAPI property using the Fields collection is:
Obtain a reference to the Fields collection of the CDO object whose property is to be read or written.
From the Fields collection, ...
Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.