How to use CDO (1.x) to read MAPI Address Book properties

Article translations Article translations
Article ID: 179083 - View products that this article applies to.
This article was previously published under Q179083
Expand all | Collapse all

SUMMARY

This article provides an example of how to use Visual Basic to retrieve some of the more common fields available in the address book. This article also shows how to use a filter on the address book.

MORE INFORMATION

Create a reference to the Microsoft Collaboration Data Objects (1.2, 1.21) Library and copy the following code to a Visual Basic form:
   Option Explicit

    Private Sub Command1_Click()

       Const strServer = "MyServer"
       Const strMailbox = "MyMailbox"

       Dim objSession As MAPI.Session
       Dim objAddrEntries As AddressEntries
       Dim objAddressEntry As AddressEntry
       Dim objFilter As AddressEntryFilter
       Dim strProfileInfo As String

       strProfileInfo = strServer & vbLf & strMailbox

       Set objSession = CreateObject("MAPI.Session")
       objSession.Logon , , False, False, , True, strProfileInfo
       Set objAddrEntries = objSession.AddressLists _
                           ("Global Address List").AddressEntries
       Set objFilter = objAddrEntries.Filter
       objFilter.Fields.Add CdoPR_SURNAME, "LastName"
       objFilter.Fields.Add CdoPR_GIVEN_NAME, "FirstName"
       On Error Resume Next
       For Each objAddressEntry In objAddrEntries
          Debug.Print objAddressEntry.Name
          Debug.Print "E-address: " & objAddressEntry.Address
          Debug.Print "Given Name: " & _
                      objAddressEntry.Fields(CdoPR_GIVEN_NAME).Value
          Debug.Print "Initials: " & objAddressEntry.Fields _
                      (CdoPR_INITIALS).Value
          Debug.Print "Surname: " & objAddressEntry.Fields _
                      (CdoPR_SURNAME).Value
          Debug.Print "Display Name: " & objAddressEntry.Fields _
                      (CdoPR_DISPLAY_NAME).Value
          Debug.Print "Alias: " & _
                      objAddressEntry.Fields(CdoPR_ACCOUNT).Value
          Debug.Print "Title: " & _
                      objAddressEntry.Fields(CdoPR_TITLE).Value
          Debug.Print "Company Name: " & objAddressEntry.Fields _
                      (CdoPR_COMPANY_NAME).Value
          Debug.Print "Office Location: " & objAddressEntry.Fields _
                      (CdoPR_OFFICE_LOCATION).Value
          Debug.Print "Office Phone 1: " &  objAddressEntry.Fields _
                      (CdoPR_OFFICE_TELEPHONE_NUMBER).Value
          Debug.Print "Office Phone 2: " & objAddressEntry.Fields _
                      (CdoPR_OFFICE2_TELEPHONE_NUMBER).Value
          Debug.Print "Business Fax: " & objAddressEntry.Fields _
                      (CdoPR_BUSINESS_FAX_NUMBER).Value
          Debug.Print "Mobile Phone: " & objAddressEntry.Fields _
                      (CdoPR_MOBILE_TELEPHONE_NUMBER).Value
          Debug.Print "Pager: " & objAddressEntry.Fields _
                      (CdoPR_PAGER_TELEPHONE_NUMBER).Value
          Debug.Print "Assistant: " & objAddressEntry.Fields _
                      (CdoPR_ASSISTANT).Value
          Debug.Print "Assistant Phone: " & objAddressEntry.Fields _
                      (CdoPR_ASSISTANT_TELEPHONE_NUMBER).Value
          Debug.Print "Home Phone 1: " & objAddressEntry.Fields _
                      (CdoPR_HOME_TELEPHONE_NUMBER).Value
          Debug.Print "Home Phone 2: " & objAddressEntry.Fields _
                      (CdoPR_HOME2_TELEPHONE_NUMBER).Value
          Debug.Print "Home Fax: " & objAddressEntry.Fields _
                      (CdoPR_HOME_FAX_NUMBER).Value
          Debug.Print "Home Street: " & objAddressEntry.Fields _
                      (CdoPR_HOME_ADDRESS_STREET).Value
          Debug.Print "Home City: " & objAddressEntry.Fields _
                      (CdoPR_HOME_ADDRESS_CITY).Value
          Debug.Print "Home State: " & objAddressEntry.Fields _
                      (CdoPR_HOME_ADDRESS_STATE_OR_PROVINCE).Value
          Debug.Print "Home Postal Code: " & objAddressEntry.Fields _
                      (CdoPR_HOME_ADDRESS_POSTAL_CODE).Value
          Debug.Print "Home Country: " & objAddressEntry.Fields _
                      (CdoPR_HOME_ADDRESS_COUNTRY).Value
          Debug.Print "Manager Name: " & objAddressEntry.Fields _
                      (CdoPR_MANAGER_NAME).Value
          Debug.Print "Manager Name: " & objAddressEntry.Manager
       Next
       objSession.Logoff
       Set objFilter = Nothing
       Set objAddrEntries = Nothing
       Set objSession = Nothing
   End Sub
				

Properties

Article ID: 179083 - Last Review: May 20, 2005 - Revision: 4.0
APPLIES TO
  • Microsoft Collaboration Data Objects 1.21
  • Microsoft Collaboration Data Objects 1.2
Keywords: 
kbhowto kbmsg KB179083
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com