Application_NewMail

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 Microsoft Exchange Server mailboxes in Outlook 2000. The first is my
account mailbox and the other is an addition via the Services|Advanced tab of
the Services diaglog for the Exchange Server. The second mailbox is a generic
account that has been adminstered to give only me permission.

I have a VBA project (ThisOutlookSecssion) and the procedure
Application_Startup that starts, if new mail is waiting in either mailbox. I
have the procedure Application_NewMail that starts, if new mail is only
waiting in the first mailbox. How could I get the code to start for the
second mailbox ?
 
You'd need to set up an event handler for the other mailbox's Inbox folder using the MAPIFolder.Items.ItemAdd event.
 
What am I doing wrong ?

Dim WithEvents myFolderInbox As Outlook.MAPIFolder

Private Sub myFolderInbox_ItemAdd()
Call MsgBox("Item Added", vbOKOnly, strMailBoxName)
End Sub

Private Sub Initialize_Handler()
Dim fldInbox As Outlook.MAPIFolder ' Outlook Object Model - MAPI Folder
Dim gnspNameSpace As Outlook.NameSpace
Set gnspNameSpace = Outlook.GetNamespace("MAPI")
Set fldInbox = gnspNameSpace.Folders(strMailBoxName).Folders("Inbox")
Set myFolderInbox = fldInbox.Items
End Sub
Private Sub Application_Startup()
Call Initialize_Handler
End Sub
 
How are you setting the value of strMailBoxName? Have you checked to see whether you're getting a valid folder to sink events for?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
strMailBoxName is Hardcoded for the second mailbox and yes I can navigate the
inpox folder of that mailbox, however I'm confused on how to set up the event
handler. See Previous example.
 
Your event handler code looks fine, but do you know for sure that it's running when Outlook starts? Did you try setting a breakpoint?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
The event handler did have a problem. The following worked:

Dim WithEvents myInboxMailItem As Outlook.Items

Private Sub myInboxMailItem_ItemAdd(ByVal Item As Object)
Call MsgBox("Item Added", vbOKOnly, strMailBoxName)
End Sub

Private Sub Initialize_Handler()
Dim fldInbox As Outlook.MAPIFolder
Dim gnspNameSpace As Outlook.NameSpace
Set gnspNameSpace = Outlook.GetNamespace("MAPI") 'Outlook Object
Set fldInbox = gnspNameSpace.Folders(strMailBoxName).Folders("Inbox")
Set myInboxMailItem = fldInbox.Items
End Sub

Private Sub Application_Startup()
Call Initialize_Handler
End Sub
 
Back
Top