Application_NewMail

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

Sue Mosher [MVP-Outlook]

You'd need to set up an event handler for the other mailbox's Inbox folder using the MAPIFolder.Items.ItemAdd event.
 
G

Guest

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
 
S

Sue Mosher [MVP-Outlook]

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
 
G

Guest

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

Sue Mosher [MVP-Outlook]

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
 
G

Guest

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
 

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