How to resolve a "TO" recipient to a contact item?

J

James Klimek

Hi - When the a recipient is added to the To field of the
mail item form, I need to get the first "TO" recipient
item listed and then retrieve the contact item.

For some reason, I can't seem to get the contact. I want
to avoid iterating over the contacts folder comparing
each contact to the recipient.

I have the following VBA code in my my form:

Sub Item_PropertyChange( ByVal Name )
If (Name = "To")Then
LookupContact
End If
End Sub

Sub LookupContact()

' Get the first recipient in the list - will add more
' code here later to make sure its type is TO
Dim oRecipient
Set oRecipient = Item.Recipients(1)

Dim sRecipientEID
sRecipientEID = oRecipient.EntryID

Dim oNS
Set oNS = Item.Application.GetNamespace("MAPI")

Dim oContactsFolder
Set oContactsFolder = oNS.GetDefaultFolder(10)

Dim sStoreID
sStoreID = oContactsFolder.StoreID

Dim oContact
Set oContact = oNS.GetItemFromID(sRecipientID, sStoreID)

If (Not oContact Is Nothing) Then
' Do something useful with my contact
Else
msgbox "Contact Found!"
End If
End Sub

Anyone have a thoughts or suggestions?

Thanks!
- Jim
 
K

Ken Slovak - [MVP - Outlook]

You should be able to get the recipient Name and use that as a filter or
restriction on the Items collection of the contacts folder using Name to
filter on "[FullName]". Of course you might have to check multiple contacts
folders.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top