Outlook: .Move partially failing

LEXCERM

Registered User.
Local time
Today, 14:23
Joined
Apr 12, 2004
Messages
169
Hi all,

I have code which iterates the contents of an email folder and saves the message body of each email to a text file. I also have options to select date range etc using the ReceivedTime property. This works without fail.

What I am also doing is once the data has been copied over to the text file, to move the email to a different folder using the same date variables etc. The problem I have is that it doesn't move all of the emails. It looks like it misses every other one or two.

Is there a generic issue that I am not aware of regading .Move?

Thanks in advance.
 
Finally found the answer elsewehere:

"[The removing of objects (your mailitems) from your folder is throwing off the position of each mailitem in the collection. For example if you have 11 elements it moves the first your for statement believes is done with element 1 however because you have removed element one all other elements have been re-indexed therefore when it goes to element 2 it is skipping the original element 2 (which is now element 1) and moving the element which was originally element 3.]"

This applies if you are using a for each loop, apparently (which I was). Have changed to With/Wend and it works!!!!
 

Users who are viewing this thread

Back
Top Bottom