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

  • Thread starter Thread starter James Klimek
  • Start date Start date
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
 
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.
 
Back
Top