title: VBA Outlook - Some MailItems produce runtime error 430
body: <p><br>
  I am currently working on a simple VBA macro wich collects some metadata (e.g. <code>EntryId</code>, <code>ReceivedTime</code>, <code>Recipients</code> etc...) of mails in an Outlook mailbox.<br>
  To accomplish this it iterates through all folders recursively and collects the data from <code>MailItems</code> in every folder.</p>
  
  <p>But I'm getting errors, which are not restricted to the same object (sometimes the error pops up earlier, but never later), stating the object does not support automation (runtime error <code>430</code>).</p>
  
  <p>The strange thing is, that roughly 14000 <code>MailItems</code> are processed without failure and usually at number 14232 it crashes.</p>
  
  <p>I have two questions regarding this error:<br></p>
  
  <ol>
  <li>I am working on a non local mailbox, therefore only a part of the data should be cached in the local <code>.ost</code> file.<br>Could data missing in the cache be the cause for the error?</li>
  <li>And if the cache is not the problem, then what is wrong with my code?</li>
  </ol>
  
  <p>A simplified version of the code:<br>
  (Please note that all non <code>MailItem</code> objects are ruled out via an explicit typecheck)</p>
  
  <pre><code>Sub cache()
      Dim objOl As Outlook.Application
      Dim objNs As Outlook.NameSpace
      Dim folder As Outlook.MAPIFolder
      Dim vFolders As Outlook.Folders
  
      Set objOl = New Outlook.Application
      Set objNs = objOl.GetNamespace("MAPI")
      Set vFolders = objNs.Folders
  
      'This is where we're looking for the mailbox to work with
      For i = 1 to vFolders.count
          If StrComp(vFolders(i), "The Mailbox") = 0 Then
              walk vFolders(i)
          End If
      Next
  End Sub
  
  Sub walk(folder As Outlook.MAPIFolder)
      Dim item As Object
      Dim vItems As Outlook.Items
      Set vItems = folder.Items
  
      If vItems.count &gt; 0 Then
          For i = 1 to vItems.Count
              Set item = vItems(i)
              If item.class = 43 Then
                  'This is where the debugger shows the runtime error 430
                  Debug.Print item.EntryID &amp; vbCrLf &amp; item.ReceivedTime
              End If
          Next
      End If
  
      Dim vFolders as Outlook.Folders
      Set vFolders = folder.Folders 
      If (vFolders.count &gt; 0) Then
          For i = 1 To vFolders.Count
              walk vFolders(i)
          Next
      End If
  End Sub
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I updated the code according to the suggestions. No multi-dot notation and no <code>For Each</code> loops, the performance increased but the problem keeps occuring at the exact same item, as soon as I try to access data like (subject, entryID or else).</p>