Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004

    Unanswered: for (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
    If email.Attachments.Count>0
    For Each atmt in email.Attachments
    'save attachment to hard drive
    'create record in my table (DAO)
    Next atmt
    'move email to folder Archive
    'do nothing; leaving email in Inbox
    End If
    Next email

    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 loop is the source of the problem (I am screwing up the enumeration).

    I was going to replace the "for each" 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?


  2. #2
    Join Date
    Mar 2004

    Re: for (altering collection at runtime)

    Instead of using for use a simple for loop and count down instead of up. i.e.

    For iCounter=InBox.Items.Count to 0 step -1
    Next iCounter

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts