Folder Events on delegates folder

  • Thread starter Thread starter R
  • Start date Start date
R

R

Hi again

Is it possible to trigger an event on a delegates non default folder?
I am trying to monitor when items are added in an additional mailbox folder
(not an outlook default folder).

I tried to expand on my last code posted here but am stuck again. After
searching outlookcode.com I found an article that may contain what I need
however the link is broken ( http://www.outlookcode.com/d/quarexe.htm )

Can someone please direct me? Many thanks.

MY CODE:

Private WithEvents oFolder As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Dim myRecipient As Outlook.Recipient
Dim oFolder As Outlook.MAPIFolder

Set objNS = Application.GetNamespace("MAPI")

Set myRecipient = objNS.CreateRecipient("Barrier Officer") 'added
myRecipient.Resolve 'added

' instantiate objects declared WithEvents and get folder ID
Set oFolder =
objNS.GetFolderFromID("000000007139C0E6E9F42F4A9F4C380E252FAE020100EFA5DC80F953CF42BDA628FB9C468E630000007383EA0000")
'If oFolder.Items.Count > 0 Then MsgBox "new mail" 'used
to debug, this works
Set objNS = Nothing
End Sub

Private Sub oFolder_ItemAdd(ByVal Item As Object)
On Error Resume Next

' If Item.UnRead = True Then
' MsgBox "You have an unread item in Receipts folder"
' End If

If oFolder.Items.Count > 0 Then MsgBox "New Email in Receipts folder!",
vbOKOnly + vbInformation

Set Item = Nothing
End Sub
 
Yes, you should be able to get events from another user's folder, if the folder is visible in the current user's Folder List. One problem with your code is that you have oFolder declared as an Items object, but are returning it from GetFolderFromID. It needs to be declared as a MAPIFolder object, with a separate Items object used for WithEvents. Also, you'll probably need to use both the folder's EntryID and its StoreID to return it from GetFolderFromID.
 
I cannot use MAPIfolder as an event though? It does not accept it.
Do you have an example I can follow please???? Im hopeless without them.

Ive changed the event line to Private WithEvents FolderItems As Items and
have declared Dim oFolder As Outlook.MAPIFolder

Thanks


Yes, you should be able to get events from another user's folder, if the
folder is visible in the current user's Folder List. One problem with your
code is that you have oFolder declared as an Items object, but are
returning it from GetFolderFromID. It needs to be declared as a MAPIFolder
object, with a separate Items object used for WithEvents. Also, you'll
probably need to use both the folder's EntryID and its StoreID to return it
from GetFolderFromID.
 
As I said, you need to have an Items object declared WithEvents in order to use its ItemAdd or other events:

Private WithEvents FolderItems As Items
Dim oFolder As Outlook.MAPIFolder

<snip>

strEntryID = "000000007139C0E6E9F42F4A9F4C380E252FAE020100EFA5DC80F
953CF42BDA628FB9C468E630000007383EA0000"
strStoreID = <?????> ' you will need to determine this ID
Set oFolder = objNS.GetFolderFromID(strEntryID, strStoreID)
Set FolderItems = oFolder.Items
 
Back
Top