ItemAdd event not firing every time

  • Thread starter Thread starter joebob
  • Start date Start date
J

joebob

I added the code below to fire whenever I receive an item. I then
compiled, closed Outlook, and sent 6 messages to myself from outside
using different addresses. I then opened Outlook and downloaded the 6
messages but MsgBox only fired twice. Is there a mechanism that will
successfully capture every incoming item? This is for O2K SP3 CW mode.
Thanks

Private WithEvents olInboxItems As Items

Private Sub Application_Startup()

Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing

End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)

If Item.Class = olMail Then
MsgBox ""
End If

End Sub
 
ItemAdd won't fire if too many items come in at once and it won't fire if
you are already within an ItemAdd handler (no reentrancy for interrupt
service routines). Six items shouldn't be too many to fire but a MsgBox is
modal until you close it so you are probably spending too much time in the
ItemAdd handler.

Instead of using MsgBox, replace that line for testing with Debug.Print
Item.Subject

That will run much faster and I predict that you will fire all six times.
 
Back
Top