
Object Types don't match message
Hi all,
I'm trying to find and efficient method of selecting a contact based on its
name and found some code that seems to do it.
In the following codesample, I get a types don;t match error when i remove
the debug.print statement. With the debug.print it seems to function
allright. It seems inefficient to me to leave it there, since I only put it
there for debugging reasons. Can anyone please solve this puzzle and give me
a sollution? I can't declare objItem as ContactItem, because then i get a
runtime error on the object colItems. If there is a better method to find a
contact based on an attribute-value I would be very interested also.
Thanks very much in advance.
The declaration of object:
Dim olItem As Outlook.ContactItem
Dim colItems As Items
Dim objItem As Object
Dim olNameSpace As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim olNewFolder As Outlook.MAPIFolder
Set olItem = Nothing
strWhere = "[FileAs] = " & """" & strItemName & """"
Set colItems = olNewFolder.Items.Restrict(strWhere)
colItems.SetColumns ("FileAs")
For Each objItem In colItems
' must test for item type to avoid distribution lists
If TypeName(objItem) = "ContactItem" _
Then
If objItem.FileAs = strItemName _
Then
Debug.Print "Item = " & objItem
Set olItem = objItem
Exit For
End If
End If
Next
Kind regards,
Hans