objInboxItems_ItemAdd

  • Thread starter Thread starter Slava
  • Start date Start date
S

Slava

Hi,

I want to set up a simply test project: at Inbox, when new email will
arrive,
then simply message will be displayed :

ThisOutlookSession :
Private Sub Application_Quit()
Set objInboxItems = Nothing
End Sub

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub


Inserting : Class Modules : objInboxItems :


Private WithEvents objInboxItems As Items

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
MsgBox "New Item Subject: " & Item.Subject
End Sub


save/compile project,
closing Outlook, starting Outlook,
then will appeare dialog about Macro-s, I accept macros,
new email will arrive, but no MsgBox :o((

what is wrong in this simply example ?


thank you for any idea,
slava
 
If you put in an Option Explicit statement in your modules, you'd quickly see the problem: You're trying to instantiate objInboxItems in ThisOutlookSession, when objInboxItems is a private variable in a class module.

The easiest fix is to put all the code in ThisOutlookSession.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Back
Top