none
Move to folder outside Inbox with VSTO RRS feed

  • Question

  • This is my mailbox (abbreviated names of course). I wish to transfer mail items from the inbox to the bu folder and add handler to check for new unread items within the bu folder.

    For the life of me I cannot get the code to work (Object reference not set). I'm using the code below somewhat out of context. But it seems im trying to attach to the folder but the folder isn't there.

    olMail = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox)

    AddHandler olMail.Items.ItemRemove, AddressOf Mail_Sorting
    AddHandler olMail.Folders("Builds").Items.ItemAdd, AddressOf Mail_Process

    Any ideas?

    Tuesday, June 19, 2012 4:31 PM

Answers

  • You code is assuming that "Build" is below Inbox. Your picture shows it to be at the same level as Inbox:
     
    Dim olBuilds As Outlook.Folder = olMail.Parent.Folders("Build")
     
    You also will need to establish object variables for each Items collection at a class level so your objects don't go out of scope and get garbage collected when the procedure where they're set ends. As it is, the handlers will fail to fire after a while.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "_Ritchie_" <=?utf-8?B?X1JpdGNoaWVf?=> wrote in message news:81a016dd-2ca6-4487-b70d-2bd15474b220...

    This is my mailbox (abbreviated names of course). I wish to transfer mail items from the inbox to the bu folder and add handler to check for new unread items within the bu folder.

    For the life of me I cannot get the code to work (Object reference not set). I'm using the code below somewhat out of context. But it seems im trying to attach to the folder but the folder isn't there.

    olMail = Me.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox)

    AddHandler olMail.Items.ItemRemove, AddressOf Mail_Sorting
    AddHandler olMail.Folders("Builds").Items.ItemAdd, AddressOf Mail_Process

    Any ideas?


    Ken Slovak MVP - Outlook
    Tuesday, June 19, 2012 4:55 PM