Unique identifier for Contacts in a MAPI folder?

E

Ed Adamthwaite

Hi all,
I am wondering if there is a unique identifier for contacts in a MAPI
folder. I am using the function below to see if a Contact exists, however if
there are 2 "Fred Smiths" and the first one checked doesn't have the correct
Email1address, it won't check for existance of the second.
I cannot find a way to force a check for second existance of "Fred Smith".
Any ideas?

Thanks for any replies.
Ed.

Function DoesContactExist(FirstNameAndLastName As String, _
Email1address As String) As Boolean
On Error GoTo ErrorHandler
Dim olApp As Outlook.Application
Dim olNameSpace As NameSpace
Dim olFolder As Outlook.MAPIFolder
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderContacts)
With olFolder
' Debug.Print "email is " & .Items(FirstNameAndLastName).Email1address
If .Items(FirstNameAndLastName).FullName = FirstNameAndLastName _
And .Items(FirstNameAndLastName).Email1address = Email1address Then
DoesContactExist = True
End If
End With
GoTo ThatsIt
ErrorHandler:
DoesContactExist = False
ThatsIt:
Set olFolder = Nothing
Set olNameSpace = Nothing
Set olApp = Nothing
End Function
 
E

Ed Adamthwaite

Found it! but it is so slowwwwww.....


Dim olContactItem As Outlook.ContactItem

For Each olContactItem In .Items

If olContactItem.FullName = FirstNameAndLastName _

And olContactItem.Email1address = Email1address Then

DoesContactExist = True

GoTo ThatsIt

End If

Next
 
M

Michael Bauer

Hi Ed,

you can use the Restrict function. It returns a collection with all
items found.
 
J

John Riddle

You could also do a .Find() ...FindNext() on the items collection of the
folder. Much faster than a For...Next loop. Be sure to use a Do... While... to
test for the last item. Something like a

Set myItem = oItems.Find(strCriteria)
Do While TypeName(myItem) <> "Nothing"
'Code here to process item
Set myItem = oItems.FindNext
Loop

This is just from memory. I'm sure there are mistakes in the sample above, but
should get you on the right track. This method has been the fastest I've found
to find multiple items in large collections without using ExMapi or
Redemption.

John

Hi all,
I am wondering if there is a unique identifier for contacts in a MAPI
folder. I am using the function below to see if a Contact exists, however if
there are 2 "Fred Smiths" and the first one checked doesn't have the correct
Email1address, it won't check for existance of the second.
I cannot find a way to force a check for second existance of "Fred Smith".
Any ideas?

Thanks for any replies.
Ed.

Function DoesContactExist(FirstNameAndLastName As String, _
Email1address As String) As Boolean
On Error GoTo ErrorHandler
Dim olApp As Outlook.Application
Dim olNameSpace As NameSpace
Dim olFolder As Outlook.MAPIFolder
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderContacts)
With olFolder
' Debug.Print "email is " & .Items(FirstNameAndLastName).Email1address
If .Items(FirstNameAndLastName).FullName = FirstNameAndLastName _
And .Items(FirstNameAndLastName).Email1address = Email1address Then
DoesContactExist = True
End If
End With
GoTo ThatsIt
ErrorHandler:
DoesContactExist = False
ThatsIt:
Set olFolder = Nothing
Set olNameSpace = Nothing
Set olApp = Nothing
End Function
 

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