ItemAdd not firing

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
 
K

Ken Slovak - [MVP - Outlook]

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.
 
M

mlafarlett

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?
 
K

Ken Slovak - [MVP - Outlook]

A Do loop with calls to DoEvents (or whatever the .NET equivalent of that
is) might work better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top