Skip to Content
CDO & MAPI Programming with Visual Basic:
book

CDO & MAPI Programming with Visual Basic:

by Dave Grundgeiger
October 2000
Intermediate to advanced
384 pages
10h 22m
English
O'Reilly Media, Inc.
Content preview from CDO & MAPI Programming with Visual Basic:

Creating a Contact

Because contacts are stored as message items in the MAPI system, creating a contact is just like creating a new message. The steps to create a new contact are:

  1. Obtain a reference to the Messages collection of a contacts folder.

  2. Invoke the Messages collection’s Add method to create a new contact item as a Message object.

  3. (Optional) Set properties of the new contact item.

  4. Invoke the Message object’s Update method to save the contact in the message store.

Example 10-6 shows how to create a new contact, setting some additional properties at the same time. This code makes use of the LetMAPIProperty subroutine shown in Example 10-4. Figure 10-1 shows the newly created contact, as displayed by Microsoft Outlook 98.

Tip

As was the case with task items, some contact item properties are inaccessible. One of these properties is the “file as” setting in Outlook. This is the setting that labels each contact in Outlook’s Address Card view. Therefore, contacts created programmatically appear to have no name when looked at in this view. CDO does not provide a workaround for this.

Example 10-6. Creating a Contact

' 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 Contacts folder. Set CdoFolder = gCdoSession.GetDefaultFolder(CdoDefaultFolderContacts) ' Get the collection of Contacts. Set CdoMessages = CdoFolder.Messages ' Add a new Contact. Set CdoMessage = CdoMessages.Add(Subject:="Jane ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
COM Programming with Microsoft® .NET

COM Programming with Microsoft® .NET

John Paul Mueller, Julian Templeman

Publisher Resources

ISBN: 156592665XSupplemental ContentCatalog PageErrata