ItemAdd not firing

  • Thread starter Thread starter mlafarlett
  • Start date Start date
M

mlafarlett

I've seen this post numerous times but can't seem to derive the
resolution...I've written a very small test app (see below) to
demonstrate. My end goal is to have an app to continually monitor the
inbox for new entries and process them according to subject , however,
the event never fires. Thanks in advance, Michael

Imports Outlook = Microsoft.Office.Interop.Outlook


Module subMain
Dim WithEvents oRcvdItems As Outlook.Items
Sub main()

Dim oOL As Outlook.Application
Dim oNS As Outlook.NameSpace

oOL = CreateObject("Outlook.Application")
oNS = oOL.GetNamespace("MAPI")
oRcvdItems =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items

'Sleep forever so we can wait on stuff to show up ( IS THERE A BETTER
WAY TO DO 'THIS?)

SleepForAwhile:
System.Threading.Thread.Sleep(15000)
GoTo SleepForAwhile

oOL = Nothing
oNS = Nothing
oRcvdItems = Nothing
End Sub

Private Sub oRcvdItems_ItemAdd(ByVal Item As Object)
Debug.WriteLine(Item.subject)
End Sub


End Module
 
Questions like this are best posted in a programming group like
microsoft.public.outlook.program_vba.

Why are you sleeping the application? That's probably what's preventing your
event handler from firing.
 
I'll move the post..sorry..wasn't sure where....sleeping? well..i
don't know how else to keep the program alive and keep it from falling
through sub main and terminating...suggestions?
 
A Do loop with calls to DoEvents (or whatever the .NET equivalent of that
is) might work better.
 
Back
Top