Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move Outlook Messages with VB Duplication Problem 1

Status
Not open for further replies.

mrgulic

Technical User
Sep 18, 2001
248
US
This code goes to each subfolder in the INBOX, looks at the message and compares its date value to a variable (the previous month).

If the message matches the previous month then it will move the message to the archive folder and continue processing the next messages in the same manner.

In this case all messages recieved in May will get moved and messages from June are left alone.

The problem is that it processes the first few messages correctly then it starts making duplicates (4 to 6 of them) when it moves them and then doesn't seem to complete it's processing of all the messages in the folder because several from the previous month are still there.

Code:
For Each objFolder In myNowFolder.Folders
  Set myNewFolder = myNS.Folders("Mailbox - FMAAMON").Folders("Archive").Folders(strYear).Folders(strMonth).Folders.Add(objFolder)
  Set myNowSubFolder = myNS.Folders("Mailbox - FMAAMON").Folders("Inbox").Folders("Monitoring").Folders(CStr(objFolder))
  iMax = myNowSubFolder.Items.Count
    For i = 1 To iMax
    Set myItem = myNowSubFolder.Items(i)
      If Format(myItem.ReceivedTime, "mm") = strMonth Then
        myItem.Move myNewFolder
      End If
    Next i
Next objFolder
 
What about replacing this:
For i = 1 To iMax
with this ?
For i = iMax To 1 Step -1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top