Unanswered: for each...next (altering collection at runtime)
I am creating a record for each email attachment received in Inbox (in Outlook) then moving the email to folder Archive (in Outlook). This is not a syntax question. Here is the basic layout of my procedure:
For Each email in Inbox.Items
For Each atmt in email.Attachments
'save attachment to hard drive
'create record in my table (DAO)
'move email to folder Archive
'do nothing; leaving email in Inbox
This procedure works fine but I have to run it several times before it will go through all of the emails (it checks only a few of the emails each time but eventually gets them all if I run the procedure enough times). The fact that I am removing emails from the collection within the for each..next loop is the source of the problem (I am screwing up the enumeration).
I was going to replace the "for each email...next" with a "while Inbox.Items.Count > 0...wend" but I want any emails without attachments to stay in Inbox. If no one has a better idea I will have to use this method but move emails with no attachments into a third Outlook folder (e.g. NoAttachmentsBox). Does anyone have a better idea?
Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!
Or try our Ask An Expert service to answer any of your questions!