HOWTO: Read Address Book Properties in Visual Basic
ID: Q179083
|
The information in this article applies to:
-
Collaboration Data Objects (CDO), versions 1.2, 1.21
-
Microsoft Visual Basic Standard and Enterprise Editions for Windows, versions 4.0, 5.0
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 (CDO) 1.2
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
Additional query words:
ActMsg
Keywords : kbCDO120 kbCDO121 kbMsg kbVBp400 kbVBp500 kbGrpMsg
Version : WINDOWS:1.2,1.21,4.0,5.0
Platform : WINDOWS
Issue type : kbhowto