View Single Post
  #2  
Old February 22nd 10, 09:40 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default MailItem Find Method question



If strSubject is declared as a String type, it never will be Null. Instead
use IsEmpty, or even better just:

If str="" then...

Actually you'd need the LIKE operator in the filter, but that's not
supported. So you'd have to loop through all the collection, and check each
item with
If item.subject like "*whatever*" Then ...

More flexible, and a lot faster, are the Restriction* objects from the
Redemption (www.dimastr.com)

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
http://www.vboffice.net/product.html?pub=6&lang=en


Am Sun, 21 Feb 2010 15:28:08 -0800 schrieb Salad:

Using the Find method to find a Subject, I have a couple of questions.
If the Subject is "Test", the following code finds the email. If the
subject is " Test", it does not. I have to remove the prefix. Why
is that?

If the subject is null, my code doesn't find the email. I figure
someone can send an email without a subject. Any idea on correcting it?

If Not IsNull(strSubject) Then
Set objMail = _
objNS.GetDefaultFolder(6).Items.Find("[Subject] = """ & _
strSubject & """")
Else
Set objMail = _
objNS.GetDefaultFolder(6).Items.Find("[Subject] Is Null")
End If

I have a question on finding the email by date as well. I pass a date
field to the function. It converts the date time to a string then
searches. Out of 10 email times passed to it, if found only 1. Any
idea whay the code below fails the majority of the time?

strTime = Format(datTime, "m/d/yyyy h:nn AMPM")
Set objMail = objNS.GetDefaultFolder(6).Items.Find("[ReceivedTime]= """
& strTime & """")

Ads