title: Move Outlook emails from one folder to another using VB.NET
body: <p>Does anybody know how to move a set of emails from one outlook folder to another based on som qualifying function (i.e. not all emails) ?
  I have the following code which works ok for the first qualifying email, but not the second or third...
      Dim objOL As Outlook.Application = New Outlook.Application<br>
      Dim objNS As Outlook.NameSpace = objOL.GetNamespace("MAPI")<br>
      olSourceFolder = objNS.Folders(MailboxIndex).Folders(3)  ' (3 by way of example)<br>
      Dim myItems As Outlook.Items = olSourceFolder.Items  </p>
  
  <pre><code>Dim i As Integer = 1  
  Dim M As Outlook.MailItem  
  
  Do While i &lt;= myItems.Count  
    M = myItems(i)  
    If qualifyingFunction(M)  
      M.Move(olDestinationFolder)  
    Else 
      i = i + 1  
    End If 
  Loop 
  </code></pre>
  
  <p>After a "move", M will not be correctly assigned the next time around
  I am guessing I dont really know how I should be iterating through the emails ??
  Thanks.</p>