AddressList.GetContactsFolder Method (Outlook)
Obtains a Folder object that represents the Contacts folder for the AddressList object.
Version Information
Version Added: Outlook 2007
Syntax
expression .GetContactsFolder
expression A variable that represents an AddressList object.
Return Value
A Folder object that represents the Outlook Contacts folder for the AddressList. Returns Null (Nothing in Visual Basic) if no Outlook contacts folder is found.
Remarks
This method allows you to match an AddressList for the Contacts folder that you would like to set up as the initial address list in the Select Names dialog box.
Example
The following code sample shows you how to initialize the Select Names dialog box with the AddressList for the default Contacts folder. It first obtains the Folder object for the default Contacts folder, and looks for its AddressList by comparing the Entry ID of this Folder object with the Entry ID of the Folder object assoicated with each AddressList in the current session until it finds a match. It then sets the InitialAddressList property and displays the Select Names dialog box.
Sub SetContactsFolderAsInitialAddressList()
Dim oMsg As MailItem
Set oMsg = Application.CreateItem(olMailItem)
Dim oDialog As SelectNamesDialog
Set oDialog = Application.Session.GetSelectNamesDialog
Dim oAL As AddressList
Dim oContacts As Folder
Set oContacts = _
Application.Session.GetDefaultFolder(olFolderContacts)
On Error GoTo HandleError
'Look for the AddressList for the default Contacts folder
For Each oAL In Application.Session.AddressLists
If oAL.AddressListType = olOutlookAddressList Then
If oAL.GetContactsFolder.EntryID = _
oContacts.EntryID Then
Exit For
End If
End If
Next
With oDialog
.Caption = "Select Customer Contact"
.ToLabel = "Customer C&ontact"
.NumberOfRecipientSelectors = olShowTo
.InitialAddressList = oAL
'Let the selected names be the recipients of the new message
.Recipients = oMsg.Recipients
If .Display Then
'Recipients Resolved
End If
End With
HandleError:
Exit Sub
End Sub