Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the contact behind the recipient

Status
Not open for further replies.

siftach

Programmer
Jul 22, 2003
78
IL
I am trying the use the distribution lists in Outlook, but for my application I need to get the phone numbers of the contacts. The distribution list members are of type Recipient, which does not have phone numbers, but if you open a member in outlook it will give you the original contact that was added to the list.

How can I get to the recipient's original contact?
 
Some notes:
Code:
Sub FindContact()
    Dim olApp As Outlook.Application
    Dim olNS As NameSpace
    Dim olItem As Outlook.ContactItem
    Dim olContacts As Outlook.MAPIFolder
    
    Set olApp = CreateObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")
    Set olContacts = olNS.GetDefaultFolder(olFolderContacts)
    
    Set olItem = olContacts.items.Find("[Email1Address] = 'a@b.c'")
    Debug.Print olItem.BusinessTelephoneNumber
    
    Set olNS = Nothing
    Set olContacts = Nothing
    olApp.Quit
    Set olApp = Nothing
End Sub

With thanks to:
Outlook-Global Distribution List
thread707-1054640

 
This method has a few problems:

1. the contact can be in a public folder, not necesserily in the default contacts folder, which means everytime I will have to search in all the contact folders - very slow.

2. I can have two contacts with the same email address but with different phone numbers - which one should I pick?

Like I wrote, Outlook can go directly to the contact, so there must be a link between the recipient and the contact it originated from.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top