PC Review


Reply
Thread Tools Rate Thread

Why doesn't Item.ItemAdd event work?

 
 
typingcat@gmail.com
Guest
Posts: n/a
 
      10th Nov 2005
The following is a very simple VBScript to popup a massage box when new
mails arrived to the inbox.
========================================================
Dim Inbox As Folder
Dim InboxMails As Items

Private Sub Application_Startup()
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set InboxMails = Inbox.Items
End Sub

Private Sub InboxMails_ItemAdd(ByVal Item As Object)
MsgBox "Item ADD"
End Sub
Private Sub InboxMails_ItemChange(Item As Object)
MsgBox "item change"
End Sub
========================================================
I also added this to check whether InboxMails is properly set;

Private Sub Application_FolderContextMenuDisplay(ByVal CommandBar As
Office.CommandBar, ByVal Folder As MAPIFolder)
'To test InboxMails is properly set.
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set InboxMails = Inbox.Items
MsgBox "There " & InboxMails.Count & " mails in the inbox"
End Sub

When I right cliked a folder the massage box worked as I expected. Thus
I'm sure
that the InboxMails is set to an Items object. But InboxMails_ItemAdd
nor
InboxMails_ItemChange worked. I tried many times but in vein. What's
wrong
with my code? Please help me. Thank you.

 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      10th Nov 2005
The one known issue is that ItemAdd won't fire if more than 16 items are added to the folder at one time.

How about ItemChange? Is that firing for the Inbox folder? If you manually run the Application_Startup procedure, do both Items event handlers start working?

FWIW, that's not VBScript, but VBA code. There's a big difference.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


<(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> The following is a very simple VBScript to popup a massage box when new
> mails arrived to the inbox.
> ========================================================
> Dim Inbox As Folder
> Dim InboxMails As Items
>
> Private Sub Application_Startup()
> Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
> Set InboxMails = Inbox.Items
> End Sub
>
> Private Sub InboxMails_ItemAdd(ByVal Item As Object)
> MsgBox "Item ADD"
> End Sub
> Private Sub InboxMails_ItemChange(Item As Object)
> MsgBox "item change"
> End Sub
> ========================================================
> I also added this to check whether InboxMails is properly set;
>
> Private Sub Application_FolderContextMenuDisplay(ByVal CommandBar As
> Office.CommandBar, ByVal Folder As MAPIFolder)
> 'To test InboxMails is properly set.
> Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
> Set InboxMails = Inbox.Items
> MsgBox "There " & InboxMails.Count & " mails in the inbox"
> End Sub
>
> When I right cliked a folder the massage box worked as I expected. Thus
> I'm sure
> that the InboxMails is set to an Items object. But InboxMails_ItemAdd
> nor
> InboxMails_ItemChange worked. I tried many times but in vein. What's
> wrong
> with my code? Please help me. Thank you.
>

 
Reply With Quote
 
typingcat@gmail.com
Guest
Posts: n/a
 
      10th Nov 2005
I'm sorry. I think I wrote the code wrong .I replaced Dim InboxMails As
Items with Public WithEvents InboxMails As Outlook.Items, and it worked.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ItemRemove event stop firing, ItemAdd & ItemChange still work Jason Microsoft Outlook Program Addins 3 5th Mar 2009 12:24 AM
Outlook Mail Item Open Event Doesn't Work Nenad Dobrilovic Microsoft Outlook Program Addins 3 8th Oct 2008 03:28 PM
ItemAdd event with Outlook2007 =?Utf-8?B?RGF2aWRIJlA=?= Microsoft Outlook Form Programming 2 4th Jul 2006 09:29 AM
Handling the ItemAdd event =?Utf-8?B?Qm9uZ28=?= Microsoft Outlook VBA Programming 1 18th May 2005 04:02 PM
ItemAdd event Duncan Bates Microsoft Outlook Program Addins 1 30th Jul 2004 11:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:50 PM.