A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

MailItem Find Method question



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 21st 10, 11:28 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default MailItem Find Method question

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 & """")
  #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 & """")

  #3  
Old February 22nd 10, 04:47 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default MailItem Find Method question

Under the hood, Outlook searches on the PR_NORMALIZED_SUBJECT (which does
not include the prefix), not PR_SUBJECT.
Where does the strSubject come from? Do you actually store it? Or does the
user type it?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Salad" wrote in message
...
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 & """")



  #4  
Old February 22nd 10, 06:07 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default MailItem Find Method question

Dmitry Streblechenko wrote:

Under the hood, Outlook searches on the PR_NORMALIZED_SUBJECT (which does
not include the prefix), not PR_SUBJECT.
Where does the strSubject come from? Do you actually store it? Or does the
user type it?


In Access, one can do a File/Import/GetExternalData and link an inbox,
sent, etc folder and it's now a table, similar to an Excel spreadsheet.
So I'm using info from the inbox in my testing.

One of the fields is "Subject" that contains the entire subject line
" Test". Another field is "Subject Prefix" with just the "", and
"Normalized Subject" that contains "Test"

Besides the subject fields , there's also the
received/created/lastmodified columns, the email size, sender name, and
a few other fields like the body.

I thought it'd be relatively simple to find the email.
Works like a champ on the normalized subject as you noted.
I can'r find the email if the subject line is null.
I can't find the email based on any datetime stamp.
Works like a champ on message size.

But I figure there can be one or more emails with the same subject line,
same message size, or same datetimestamp. But all three? I don't think so.

Since the .Find method works fine on the subject and size fields, I'm
obviously passing the wrong filter for a null (blank) subject and for
the date.

I've tried, and failed on
.Find("IsEmpty([Subject]")
.Find("IsNull([Subject]")
.Find("[Subject] = ''")
and for dates
'Set objMail = .Find("[ReceivedTime]= '1/1/2010 3:34:00 AM'")
and Jan 1, 2010, January 1,2010, no seconds, no AM, just the date,
nothing works. Single quotes, double quotes, it doesn't seem to matter.

Based on the above, do you spot anything obvious that is in error? Or
other tests I could make? Or a link to compare my code to for finding
an email?



  #5  
Old February 22nd 10, 08:40 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default MailItem Find Method question

Searching by subject is a bad idea, to put it mildly :-) What happens if you
have multiple messsages with the same subject?
Use the EntryID property and open the item using using
Application.Session.GetItemFromID. There is no reason to search.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Salad" wrote in message
m...
Dmitry Streblechenko wrote:

Under the hood, Outlook searches on the PR_NORMALIZED_SUBJECT (which
does not include the prefix), not PR_SUBJECT.
Where does the strSubject come from? Do you actually store it? Or does
the user type it?


In Access, one can do a File/Import/GetExternalData and link an inbox,
sent, etc folder and it's now a table, similar to an Excel spreadsheet. So
I'm using info from the inbox in my testing.

One of the fields is "Subject" that contains the entire subject line "
Test". Another field is "Subject Prefix" with just the "", and
"Normalized Subject" that contains "Test"

Besides the subject fields , there's also the
received/created/lastmodified columns, the email size, sender name, and a
few other fields like the body.

I thought it'd be relatively simple to find the email.
Works like a champ on the normalized subject as you noted.
I can'r find the email if the subject line is null.
I can't find the email based on any datetime stamp.
Works like a champ on message size.

But I figure there can be one or more emails with the same subject line,
same message size, or same datetimestamp. But all three? I don't think
so.

Since the .Find method works fine on the subject and size fields, I'm
obviously passing the wrong filter for a null (blank) subject and for the
date.

I've tried, and failed on
.Find("IsEmpty([Subject]")
.Find("IsNull([Subject]")
.Find("[Subject] = ''")
and for dates
'Set objMail = .Find("[ReceivedTime]= '1/1/2010 3:34:00 AM'")
and Jan 1, 2010, January 1,2010, no seconds, no AM, just the date, nothing
works. Single quotes, double quotes, it doesn't seem to matter.

Based on the above, do you spot anything obvious that is in error? Or
other tests I could make? Or a link to compare my code to for finding an
email?




  #6  
Old February 22nd 10, 10:35 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default MailItem Find Method question

Dmitry Streblechenko wrote:

Searching by subject is a bad idea, to put it mildly :-) What happens if you
have multiple messsages with the same subject?
Use the EntryID property and open the item using using
Application.Session.GetItemFromID. There is no reason to search.

Wouldn't you know, EntryID is not one of the columns in the table tha is
created in Access if one links a folder.

Well, MS gave us/me the partial information, but not all unfortunately.
The table lets one know if there are attachments or not, but not the
attachment names nor as it appears an easy way to find the email. Thus
I'd need a way to find the email if it had attachments.


  #7  
Old February 23rd 10, 04:38 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default MailItem Find Method question

If you cannot get entry id as one of the columns, don't use
File/Import/GetExternalData.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Salad" wrote in message
m...
Dmitry Streblechenko wrote:

Searching by subject is a bad idea, to put it mildly :-) What happens if
you have multiple messsages with the same subject?
Use the EntryID property and open the item using using
Application.Session.GetItemFromID. There is no reason to search.

Wouldn't you know, EntryID is not one of the columns in the table tha is
created in Access if one links a folder.

Well, MS gave us/me the partial information, but not all unfortunately.
The table lets one know if there are attachments or not, but not the
attachment names nor as it appears an easy way to find the email. Thus
I'd need a way to find the email if it had attachments.




 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on getExchangeUser method in Outlook Add-in paresh Outlook and VBA 3 October 13th 09 08:05 PM
question about AddStore method [email protected] Outlook and VBA 2 November 27th 07 06:53 PM
Find Method and Private Meetings Tadwick Outlook and VBA 6 August 28th 07 04:56 PM
Outlook find Method Meex Outlook and VBA 4 May 4th 07 07:25 AM
MailItem.SaveAs method Mrunali Outlook - Using Forms 0 April 17th 07 03:16 PM


All times are GMT +1. The time now is 03:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.