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 / May 2005

Tip: Looking for answers? Try searching our database.

Help changing flag on messsages older than a certain date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin - 26 May 2005 17:41 GMT
Using Outlook 2000,  I'm trying to write a macro that searches through
messages in the inbox and, if they are older than 01/30/2005 and flagged for
follow up, I want to flag them complete.

I've tried several approaches but don't seem to be getting anywhere. Does
anyone have some code that can do this?

Thanks.

Kevin
Eric Legault [MVP - Outlook] - 26 May 2005 18:31 GMT
Try the code below.  Just change anything you need to in the calling MyMacro
procedure:

Sub MyMacro()
On Error GoTo MyMacro_Error

   Dim objInbox As Outlook.MAPIFolder
   Dim objNS As Outlook.NameSpace
   
   Set objNS = Application.GetNamespace("MAPI")
   Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
   SearchFolderForMessagesFlaggedForFollowUpBeforeSpecifiedDate objInbox,
#01/30/2005#
   
   Set objNS = Nothing
   Set objInbox = Nothing

   On Error GoTo 0
   Exit Sub

MyMacro_Error:
   If Err.Number <> 0 Then
       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure MyMacro of VBA Document ThisOutlookSession"
       Resume Next
   End If
End Sub

Sub SearchFolderForMessagesFlaggedForFollowUpBeforeSpecifiedDate(MailFolder
As Outlook.MAPIFolder, BeforeDate As Date)
On Error GoTo
SearchFolderForMessagesFlaggedForFollowUpBeforeSpecifiedDate_Error

   Dim objItems As Outlook.Items, objMailItem As Outlook.MailItem
   Dim strCriteria As String
   
   strCriteria = "[ReceivedTime] <= """ & BeforeDate & """ AND
[FlagRequest] = 'Follow up' AND [FlagStatus] <> 1"
   Set objItems = MailFolder.Items.Restrict(strCriteria)
   
   For Each objMailItem In objItems
       objMailItem.FlagStatus = olFlagComplete
       objMailItem.Save
   Next

   On Error GoTo 0
   Exit Sub
   
   Set objItems = Nothing
   Set objMailItem = Nothing

SearchFolderForMessagesFlaggedForFollowUpBeforeSpecifiedDate_Error:
   If Err.Number <> 0 Then
       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure SearchFolderForMessagesFlaggedForFollowUpBeforeSpecifiedDate of VBA
Document ThisOutlookSession"
       Resume Next
   End If
End Sub

Signature

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

> Using Outlook 2000,  I'm trying to write a macro that searches through
> messages in the inbox and, if they are older than 01/30/2005 and flagged for
[quoted text clipped - 6 lines]
>
> Kevin
Kevin - 26 May 2005 19:28 GMT
Eric,

Thanks for the prompt reply.  I see from your code that I was missing a few
key components in my own code.  Yours is better!  I'll save my grumblings on
the lack of good documentation and my own lack of prowess.

That said, when I run your code, it indeed processes a bunch of messages
but, for some reason, not all.  Each time I run the code it processes some
more.  Any insight as to why this might be?  Your code does not generate any
errors when I run it.

Thanks

Kevin

> Try the code below.  Just change anything you need to in the calling MyMacro
> procedure:
[quoted text clipped - 25 lines]
>
> Sub
SearchFolderForMessagesFlaggedForFollowUpBeforeSpecifiedDate(MailFolder
> As Outlook.MAPIFolder, BeforeDate As Date)
> On Error GoTo
[quoted text clipped - 37 lines]
> >
> > Kevin
Ken Slovak - [MVP - Outlook] - 26 May 2005 22:20 GMT
To jump in on Eric's thread, use a down counting For loop. As each item is
removed from the collection as it's marked complete the For loop index is
being messed with.

For i = objItems.Count To 1 Step -1
 Set objMailItem = objItems(i)
 objMailItem.FlagStatus = olFlagComplete
 objMailItem.Save
Next

Same thing applies when you delete or otherwise change the collection size
downward.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Eric,
>
[quoted text clipped - 13 lines]
>
> Kevin
Kevin - 27 May 2005 16:23 GMT
Thanks for stepping in to resolve this Ken.  I should have realized that
this was the case.

Cheers!

Kevin

> To jump in on Eric's thread, use a down counting For loop. As each item is
> removed from the collection as it's marked complete the For loop index is
[quoted text clipped - 26 lines]
> >
> > Kevin
 
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



©2008 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.