Error using AddressEntry.GetContact - need help

SmileyFtW

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
I am trying to do some automation on distribution lists, but am running into a snag. In a distribution list the GetMember method returns a Recipient object which has a limited amount of information and I want to get the Contact object represented by the Recipient. I test to make sure the recipient is resolved, but when I attempt to use the AddressEntry.GetContact method I get a run time error. What am I doing wrong or what else do I need to do?

Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myFolderItems = myFolder.Items
iCount = myFolderItems.Count
For x = 1 To iCount
If TypeName(myFolderItems.Item(x)) = "DistListItem" Then
Set myDistList = myFolderItems.Item(x)
For y = 1 To myDistList.MemberCount
Set myRecipient = myDistList.GetMember(y)
RecipientIsResolved = myRecipient.Resolved
If RecipientIsResolved = True Then
Set myAddressEntry = myRecipient.AddressEntry
Set myContactItem = myAddressEntry.GetContact '<Errors here with "The item could not be found"
With myContactItem
'Here I would be able to access all of the contact's information
End With
End If

Debug.Print myDistList.GetMember(y).Name
' If myDistList.GetMember(y).Name = myNameSpace.CurrentUser.Name Then
' MsgBox "Your are a member of " & myDistList.DLName
' End If
Next y
End If
Next x

Thanks!
David
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I could never figure when that function works and when it doesn´t. I´d use the Items.Find function of the contacts folder and search the email address myself.
 

SmileyFtW

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
I actually came at the problem from a different angle and got what I needed. I used the Restrict method on the contacts folder and then looped the restricted contact items. The Outlook object model is so convoluted compared to the Excel OM.
 

Top