want to popup a msgbox when a new post arrives in a public folder

M

Mark Gonyea

Hi,
I am trying to find a way to have a msgbox pop up whenever a new post
arrives in a specific public folder.

I have not had much luck, mostly I am using the below code. I have been
getting Type Mismatch errors. I think this is because there are some
MailItems in the list. I cannot figure out how to differntiate between them
programmatically.

Also, I tried putting this code in "This Outlook Session",
Application.NewItem but this seems to be only for new mail items in Inbox. I
cant seem to find the event for new post item in a public folder. There must
be one becuase the folder name turns bold whenever a new unread post
appears.

Any help is appreciated, to either help fix this code, or to point me to a
better way to do this.
Best Regards
Mark


Private Sub CheckPublicFolder()

Dim objOutlook As Outlook.Application
Dim Folder As Outlook.MAPIFolder
Dim nms As Outlook.NameSpace
Dim items As Outlook.items
Dim m_item As MailItem
Dim Post_item As PostItem
Dim i 'count of items

Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
Set Folder =
nms.GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A0300FCA5E51DD65
4694DB32C3FDB1F2A598C00000012402E0000")

Set items = Folder.items
For Each Post_item In items
If Post_item.UnRead = True Then
MsgBox "New message arrived in My Public Folder"
End If
Next

End Sub
 
K

Ken Slovak - [MVP - Outlook]

You need an ItemAdd handler for the Items collection of that folder. See
http://www.outlookcode.com/d/code/zaphtml.htm#cw for an example of an
ItemAdd handler for the Inbox's Items collection. You would use similar code
but instantiate it for the Items collection of that public folder.

It's not usually a good idea to hard-code a folder EntryID and for a folder
in a public folder store I would recommend also using the StoreID argument
in the GetFolderFromID method. Of course also your code would only handle
items as they came into the folder if your computer is on and Outlook is
running.

You can tell an item's type when you get the passed Item argument in ItemAdd
by either testing for the leftmost part of MessageClass being "IPM.Post" (it
might be a custom item so check for the string prefix) or by testing for
Item.Class = olPost.
 

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