Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / July 2005

Tip: Looking for answers? Try searching our database.

scan emails in the folder for certain phrase

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GEORGIA - 19 Jul 2005 18:14 GMT
I hope I am not repeating the questions but I looked and could not find it.
I don't know if this is possible but this is what I would like to do.
I receive emails everyday stating if the report ran successfully. If ran
successfully the email will simply say " successful", if not, then the email
will contain the word " reject" and has the username that was rejected.

I would like to:
Look for the latest email (most recent email)  in the folder named " Report
Status",
Search for the phrase " rejected" in the body of the email.  

I would like to run this in Acess database form.  Have command button to
search the email and if there is a rejection I would like msgbox to be the
body of the email.
If no reject email, then msgbox willl simply say " No rejects".

Can anyone help me with this?

Thank you
Eric Legault [MVP - Outlook] - 19 Jul 2005 21:27 GMT
This code will take you most of the way, you just have to pass a valid
MAPIFolder reference to the procedure and desing a custom message box form
that will be big enough to display the message body text:

Sub SearchForRejectedReports(SourceFolder As Outlook.MAPIFolder)
'The SourceFolder argument requires that a reference to the folder that is
to be searched
'be passed to this procedure
'Use either NameSpace.GetDefaultFolder, or walk the Folders collection of
any folder to get the desired
'MAPIFolder object reference

   Dim objItems As Outlook.Items, objMsg As Outlook.MailItem
   Dim intX As Integer
   
   Set objItems = SourceFolder.Items
   objItems.Sort "Received", True
   For intX = 1 To objItems.Count
       If objItems.Item(intX).Class = olMail Then
           'Found the most recent e-mail message
           Set objMsg = objItems.Item(intX)
           If InStr(1, objMsg.Body, "rejected", vbTextCompare) > 0 Then
               'This message contains the word "rejected"
               'You'll need to design a custom form to mimic a message box
that would be
               'big enough to contain the text of the message body which is
available here
               'by calling the value of objMsg.Body
               GoTo Leave:
           End If
       End If
   Next
   
Leave:
   Set objItems = Nothing
   Set objMsg = Nothing
End Sub

Signature

Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

> I hope I am not repeating the questions but I looked and could not find it.
> I don't know if this is possible but this is what I would like to do.
[quoted text clipped - 15 lines]
>
> Thank you
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.