O'Reilly logo

CDO & MAPI Programming with Visual Basic: by Dave Grundgeiger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Obtain a reference to the Fields collection of the CDO object whose property is to be read or written.

  2. From the Fields collection, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required