View Single Post
  #5  
Old May 5th 06, 05:13 PM posted to microsoft.public.outlook.program_vba
Fox via OfficeKB.com
external usenet poster
 
Posts: 5
Default Search for email in Inbox and subfolders

Ok, this is what I came up with based on you code:

Private Function ParseSubFolders(olCurrentFolder As Object, strMailSubject As
String) As Variant
Dim olMailMsg As Variant

For Each olMailMsg In olCurrentFolder.Items
If olMailMsg.Class = 43 And InStr(olMailMsg.Subject, strMailSubject)
0 Then

ParseSubFolders = olMailMsg
Exit Function
End If
Next

For Each olCurrentFolder In olCurrentFolder.Folders
If olCurrentFolder.DefaultItemType = 0 Then
ParseSubFolders olCurrentFolder, strMailSubject
End If
Next
End Function

But it seems that after I set ParseSubFolders = olMailMsg, the Exit Function
only exits at the particular level the function is at, and ParseSubFolders
becomes empty. Is there any way to retain ParseSubFolders as the functions
exit out of themselves?

Eric Legault [MVP - Outlook] wrote:
If the item is expected anywhere within the subfolders of the passed folder,
then it will be found. You can read objItem.Subject before explicitly
setting it to objMailItem to see if it matches.

Alternately, you can use the AdvancedSearch method which users fewer lines
of code to set a scope with sub-folder searching enabled.

I think I understand the code, but I am only looking for one mail item that
could be anywhere. Would I insert code to check the subject after the line:

[quoted text clipped - 36 lines]
way to adapt it to search email in the Inbox and subfolders. Can anyone help
me with this? Thanks.


--
Message posted via http://www.officekb.com
Ads