D
Dirk Kok
Hi All
I've got a weird problem. I open the Addressbook dialog and let the
user select some recipients. I then loop through the selected
collection and try to match the items with the contacts in the
contacts folder. I am unable to match the Contact using the Find
method. I am able to match the contact if I manually loop through all
the contacts and compare the exact same field. For large contact lists
this process should be to slow. Am I using the Find method incorrectly
or is there some other setting that I am unaware of.
A second question. I am using the Recipients.Name property. Won't this
property change from user to user. What is the correct property I
should be using for finding matching a recipient to a contact item in
the contacts folder.
Regards
Dirk
Some code follows below...
Dim objSession As MAPI.Session
Dim objRecipients As MAPI.Recipients
Dim objRecipient As MAPI.Recipient
Dim objApplication As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Set objApplication = CreateObject("Outlook.Application")
Set objNamespace = objApplication.GetNamespace("MAPI")
objNamespace.Logon "", "", False, False
Set objContacts =
objNamespace.GetDefaultFolder(olFolderContacts).Items
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
Set objRecipients = objSession.AddressBook(Nothing, "Recipients",
False, True)
For Each objRecipient In objRecipients
objRecipient.Resolve
' THIS FIND METHOD RETURNS NOTHING
Set objContact = objContacts.Find("[Email1DisplayName] = '" &
objRecipient.Name & "'")
If Not objContact Is Nothing Then
Debug.Print objContact.MobileTelephoneNumber
End If
' LOOPING THROUGH CONTACTS COMPARING EXACTLY THE SAME FIELD
MATCHES THE CONTACT
For Each objContact In objContacts
If objRecipient.Name = objContact.Email1DisplayName Then
Debug.Print objContact.MobileTelephoneNumber
Exit For
End If
Next objContact
Next objRecipient
errHandler:
Select Case Err.Number
Case 0
Case -2147221229
Case Else
MsgBox Err.Number & " - " & Err.Description
End Select
objSession.Logoff
objNamespace.Logoff
Set objRecipient = Nothing
Set objRecipients = Nothing
Set objSession = Nothing
Set objNamespace = Nothing
Set objApplication = Nothing
Set objContacts = Nothing
Set objContact = Nothing
Err.Clear
On Error GoTo 0
I've got a weird problem. I open the Addressbook dialog and let the
user select some recipients. I then loop through the selected
collection and try to match the items with the contacts in the
contacts folder. I am unable to match the Contact using the Find
method. I am able to match the contact if I manually loop through all
the contacts and compare the exact same field. For large contact lists
this process should be to slow. Am I using the Find method incorrectly
or is there some other setting that I am unaware of.
A second question. I am using the Recipients.Name property. Won't this
property change from user to user. What is the correct property I
should be using for finding matching a recipient to a contact item in
the contacts folder.
Regards
Dirk
Some code follows below...
Dim objSession As MAPI.Session
Dim objRecipients As MAPI.Recipients
Dim objRecipient As MAPI.Recipient
Dim objApplication As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Set objApplication = CreateObject("Outlook.Application")
Set objNamespace = objApplication.GetNamespace("MAPI")
objNamespace.Logon "", "", False, False
Set objContacts =
objNamespace.GetDefaultFolder(olFolderContacts).Items
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
Set objRecipients = objSession.AddressBook(Nothing, "Recipients",
False, True)
For Each objRecipient In objRecipients
objRecipient.Resolve
' THIS FIND METHOD RETURNS NOTHING
Set objContact = objContacts.Find("[Email1DisplayName] = '" &
objRecipient.Name & "'")
If Not objContact Is Nothing Then
Debug.Print objContact.MobileTelephoneNumber
End If
' LOOPING THROUGH CONTACTS COMPARING EXACTLY THE SAME FIELD
MATCHES THE CONTACT
For Each objContact In objContacts
If objRecipient.Name = objContact.Email1DisplayName Then
Debug.Print objContact.MobileTelephoneNumber
Exit For
End If
Next objContact
Next objRecipient
errHandler:
Select Case Err.Number
Case 0
Case -2147221229
Case Else
MsgBox Err.Number & " - " & Err.Description
End Select
objSession.Logoff
objNamespace.Logoff
Set objRecipient = Nothing
Set objRecipients = Nothing
Set objSession = Nothing
Set objNamespace = Nothing
Set objApplication = Nothing
Set objContacts = Nothing
Set objContact = Nothing
Err.Clear
On Error GoTo 0