Find method of folder collection

  • Thread starter Thread starter mookashi
  • Start date Start date
M

mookashi

In the following code im able to find a contact by his fullname but no
by any other criteria like Mobile no. Is there anyway i can get th
name and email of a contact from the contacts folder based on hi
mobile telephone no???


Contact Folder collection
Set conFol = objNS.GetDefaultFolder(olFolderContacts)

Recipients Collection
Set oRecips = objMailItem.Recipients

Recipient Object
Set oRecip = oRecips.Item(1)

Contact Item
Set conItem = conFol.Items.Find("[FullName]=" & oRecip.Name)

If conItem Is Nothing Then
Set conItem =
conFol.Items.Find("[MobileTelephoneNumber]="& oRecip.Name)))
End I
 
Two problems:

1) Your code sample below (("[MobileTelephoneNumber]="& oRecip.Name) looks
for the name in the phone number field when it needs to look for the number.
I have no idea where you expect to get the number to search for.

2) When searching for text, the search text needs to be in quotation marks:

strFind = "[FullName]=" & Chr(34) & oRecip.Name & Chr(34)
Set conItem = conFol.Items.Find(strFind)
 
hi,
thanks for your reply.
well the word "orecip.name" is indeed confusing.
orecip.name contains the name only if you have selected the contact
from the default address book of outlook.
try this out:
in the "To:" field type the mobile number of an existing contact
programmatically if you access the recipients collection now, then th
name property contains whatever is present in the To: and CC: fields.i
short what im saying is that the Name property contains the content
present in the To and CC fields
Correct me if Im wrong.

Right now I have a workaround where i loop through the contacts folde
searching for the no. However the Find method shd have done the job fo
me.



Two problems:

1) Your code sample below (("[MobileTelephoneNumber]="& oRecip.Name
looks
for the name in the phone number field when it needs to look for th
number.
I have no idea where you expect to get the number to search for.

2) When searching for text, the search text needs to be in quotatio
marks:

strFind = "[FullName]=" & Chr(34) & oRecip.Name & Chr(34)
Set conItem = conFol.Items.Find(strFind)
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.asp
 
I don't have any context to refer to here. You can search the contacts
folder for either a name or an address. Outlook can do both. What you can't
do is search the phone number field for a name.
 
Back
Top