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