none
Outlook Macro to GetProperty "In Folder" for a Task RRS feed

  • Question

  • I'm running this macro in Outlook 2010 x64 Pro Plus (14.0.7106.5003) and macros have been enabled.

    I'm trying to retrieve the "In Folder" property value.

    Sub TEST_02()
      Dim Session As Outlook.NameSpace
      Dim TaskFolder As Outlook.Folder
      
      Dim currentItem As Object
      Dim currentTask As TaskItem
      Dim propertyAccessor As Outlook.propertyAccessor
      
      Set Session = Application.Session
      Set TaskFolder = Session.GetDefaultFolder(olFolderTasks)
      
      Dim strProperty, strCompany, strInFolder As String
      
      On Error GoTo ErrHandler:
      For Each currentItem In TaskFolder.Items
        If (currentItem.Class = olTask) Then
          Set currentTask = currentItem
          Set propertyAccessor = currentTask.propertyAccessor
                
          strProperty = "http://schemas.microsoft.com/mapi/proptag/0x0E05001F"
          strInFolder = currentItem.propertyAccessor.GetProperty(strProperty)
          MsgBox (strInFolder)
        End If
      Next
      Exit Sub
    ErrHandler:
      MsgBox (Err & ": " & Error(Err))
    End Sub

    The code fails on the GetProperty line and ErrHandler returns the message:

        -2147221233: The property http://schemas.microsoft.com/mapi/proptag/OxOEO5001F is unknown or cannot be found.

    According to OutlookSpy, http://schemas.microsoft.com/mapi/proptag/OxOEO5001F is the valid tag for the "In Folder" property and OutlookSpy returns the correct folder name.

    Does anyone know why I'm getting this error and how do I correct it?

    Monday, December 30, 2013 9:39 PM

Answers

  • PR_PARENT_DISPLAY property is only available in the in the folder contents table, but not on messages themselves.

    In OutlookSpy, click IMAPIFolder, go to the GetContentsTable tab, click SetColumns, add the property - it will be visible in the contents table. Now click IMessage, right click, select "IMAPIProp::GetProps", type the property name - it will not be available.

    If you only need the parent folder name, why not use currentTask.Parent..Name?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Floyd Chan Thursday, January 2, 2014 9:28 PM
    Tuesday, December 31, 2013 12:56 AM

All replies

  • PR_PARENT_DISPLAY property is only available in the in the folder contents table, but not on messages themselves.

    In OutlookSpy, click IMAPIFolder, go to the GetContentsTable tab, click SetColumns, add the property - it will be visible in the contents table. Now click IMessage, right click, select "IMAPIProp::GetProps", type the property name - it will not be available.

    If you only need the parent folder name, why not use currentTask.Parent..Name?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Floyd Chan Thursday, January 2, 2014 9:28 PM
    Tuesday, December 31, 2013 12:56 AM
  • Hi Flogo,

    The related property page in MSDN states the following:

    Contains the display name of the folder where a message was found during a search. These properties is not on any object. They can only appear in the contents table of a search-results folder.

    So, you can't use the PropertyAccessor object for getting the value. Instead, as Dmitry suggested, you can use the Parent property of the TaskItem class for getting the parent folder and then you can get the Name value.

    Tuesday, December 31, 2013 10:21 AM
  • Thanks for the reply Dmitry!

    The reason why I'm trying to retrieve the "In Folder" for a task in Outlook: When Microsoft Project Server 2010 creates a synchronized task in Exchange for a user, it populates the "In Folder" field with the project name. So I am trying to retrieve the project name associated to the task.

    If I use currentTask.Parent.Name, it appears to only return the value "Tasks" for all tasks.

    I hope this add more clarity to the problem.

    BTW, Happy New Year!

    Wednesday, January 1, 2014 8:43 PM
  • Hi Eugene -

    Thanks for the response. Unfortunately, that doesn't quite work for me. I've added some additional information in my response to Dmitry.

    Happy New Year to you as well!

    Wednesday, January 1, 2014 8:45 PM
  • In Folder" returns the name of the parent folder. I don't know which property Project Server reads, but it is certainly not the name of the parent folder.

    Is it possible that Project Server (I am not familiar with it) show a property only available in Project Server? Do you see anything if you look at the task with OutlookSpy (click IMessage)?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, January 1, 2014 10:14 PM
  • Let's go one level deeper into the rabbit hole :) ... and I apologize in advance: I've been away from VB/VBA coding and the MSFT stack for a very long time, so my code and points of reference may not be correct.

    In the Outlook client, I had created a new task view that includes "In Folder" column (which is available from the pick list of Task columns). All tasks that were create in Project Server show up in Outlook task view with the "In Folder" column populated with the project name from Project Server. And it is not the same value as currentTask.Parent.Name.

    You are correct that the property does not show up in OutlookSpy as part of IMessage.

    The property and correct value does show up if I use OutlookSpy > IMAPIFolder > GetContentsTable tab > select task in left pane > find PR_PARENT_DISPLAY_W in right pane

    I am also using the "In Folder" column for a similar use for other tasks that is independent of Project Server and perhaps you can use this scenario to debug...

    1. Open the Outlook client
    2. Go to the Mail area
    3. Create a new Mail folder "For Review" that is at the same level as the Inbox
    4. Go to your Inbox
    5. Set an email
    6. Set a Follow Up flag for that email. This will also turn the email into a task.
    7. Drag the email to the "For Review" folder

    At this point if you go to your task list and add the "In Folder" column, you will see that the task has the value "For Review".

    Again, in this scenario as well, I'd like to be able to retrieve the "In Folder" value for the task programmatically.

    Wednesday, January 1, 2014 11:24 PM
  • In that scenario, after you drag the message to the "For Review" folder, it's parent will be the "For Review" folder. And Parent.Name will return "For Review".

    Is that not what you see in OutlookSpy? Click the Item button on the OutlookSpy ribbon, select the Parent property, click Browse, select the Name property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, January 1, 2014 11:43 PM
  • Dmitry, you are correct.

    OutlookSpy does show "For Review" as the value for the parent name property.

    Then the problem now must be in how I've tried to change the code.

    In the code that I originally posted, I changed the line:

    strInFolder = currentItem.propertyAccessor.GetProperty(strProperty)

    To:

    strInFolder = currentItem.Parent.Name

    When I execute this macro, the only value appearing in the MsgBox for all tasks is "Tasks".

    BTW, thanks for your patience and guidance!

    Thursday, January 2, 2014 12:24 AM
  • How do you retrieve currentItem? Does it come from TaskFolder.Items?

    Why are you working with the olFolderTasks default folder?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Thursday, January 2, 2014 12:32 AM
  • A simplified version of the code currently looks like this:

    Sub TEST_02()
      Dim Session As Outlook.NameSpace
      Dim TaskFolder As Outlook.Folder  
      Dim currentItem As Object
      Dim strInFolder As String
    
      Set Session = Application.Session
      Set TaskFolder = Session.GetDefaultFolder(olFolderTasks)
        
      For Each currentItem In TaskFolder.Items
        If (currentItem.Class = olTask) Then
          strInFolder = currentItem.Parent.Name
          MsgBox (strInFolder)
        End If
      Next
    End Sub

    As I mentioned before, I've been away from Outlook/VBA coding for a very long time and this is my first time back. I've "borrowed" the basic code structure for this from elsewhere.

    So, for the question "why are you working with the olFolderTasks default folder?"; the answer is truthfully: because I don't know any better :P

    Is there a better way to do what I've written above?

    Thursday, January 2, 2014 12:47 AM
  • Well, if you loop through the items of the Tasks folder, the Tasks folder will be the parent for all of them.

    Which folder are you actually trying to process? How exactly do you access that folder in the Outlook UI?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, January 2, 2014 1:50 AM
  • In the Outlook client, when I select "Folder List" from the navigation pane, this is an example of the possible folders where a task may reside:

    +AccountName
    ++Inbox (standard, type = mail and post items)
    ++For Review (custom, type = mail and post items)
    ++Tasks (standard, type = task items)
    +++Project A (automatically created by Project Server, type = task items)
    +++Project B (automatically created by Project Server, type = task items)
    +++Project C (automatically created by Project Server, type = task items)

    When I select "Tasks" from the navigation pane, the folders are:

    +My Tasks
    ++To-Do List
    ++Tasks
    ++Project A
    ++Project B
    ++Project C
    I should clarify that the "In Folder" column is in a view that I've been applying to the "To-Do List" folder, and I've been look at things from this perspective.

    And I just noticed that the "In Folder" column is blank when the view is applied to the "Tasks" folder. And the Parent.Name value for all these tasks is "Tasks"

    So, it appears then that I now need to ask: How do I iterate on the To-Do List?

    Thursday, January 2, 2014 5:05 PM
  • You can use the Namespace.GetDefaultFoldder(olFolderToDo) to open the To-Do search folder.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, January 2, 2014 5:24 PM
  • Thanks for everything Dmitry! That was the last piece of the puzzle!

    You've already made 2014 a good year for me :)

    Thursday, January 2, 2014 9:28 PM