After establishing a Session object and successfully logging on to the system, the user can access the address book to select recipients. You can select recipients from any address book, such as the global address list (GAL) or your personal address book (PAB).
As described in CDO Library Object Design, the CDO Library objects are organized in a hierarchy. The Session object at the topmost level contains an AddressBook method that lets your application users select recipients from an address book. The method returns a Recipients collection, which contains individual Recipient objects. The Recipient object in turn specifies an AddressEntry object. This hierarchy is shown in the following diagram.
Recipients collection
Recipient object
Address property (full address)
AddressEntry object
Address property (e-mail address, no type)
Type property
To obtain an individual Address property that can be used to address and send messages, the application must move down through this object hierarchy. The following code fragment uses the Recipients collection returned by the Session object's AddressBook method.
This code fragment assumes that the application has already created the Session object variable objSession and successfully called the Session object's Logon method, as described in Starting a CDO Session:
' Function: Session_AddressBook
' Purpose: Set the global variable that contains the current recipients
' collection to that returned by the Session AddressBook method
' See documentation topic: AddressBook method (Session object)
Function Session_AddressBook()
On Error GoTo err_Session_AddressBook
If objSession Is Nothing Then
MsgBox "Must first create MAPI session and logon"
Exit Function
End If
Set objRecipColl = objSession.AddressBook( _
Title:="Select Attendees", _
forceResolution:=True, _
recipLists:=1, _
toLabel:="&Cdo") ' appears on button
' Note: first parameter ("recipients") not used in this call
' recipients:=objInitRecipColl initializes recipients for dialog
MsgBox "Name of first recipient = " & objRecipColl.Item(1).Name
Exit Function
err_Session_AddressBook:
If (Err = 91) Then ' MAPI dlg-related function that sets an object
MsgBox "No recipients selected"
Else
MsgBox "Unrecoverable Error:" & Err
End If
Exit Function
End Function
Changing an Existing Address Entry, Using Addresses