JG7
JG7

Reputation: 371

Displaying User Defined Property of MailItem in Outlook

I am attempting to add convenience when adding notes to emails in Outlook.

My plan is to take my current procedure, which adds the notes to the selected email (as an attachment), and have it call a procedure which will set a UserProperty on the MailItem object so that I can easily see which emails have notes attached by adding a custom column to my email list view.

From scouring the internet I have pieced together the following.

Option Explicit

Public Sub MarkHasNote()
    Dim Selection As Outlook.Selection
    Dim UserDefinedFieldName As String
    Dim objProperty As Outlook.UserProperty
    Dim objItem As MailItem

    UserDefinedFieldName = "Note"
    Set objItem = GetCurrentItem()
    Set objProperty = objItem.UserProperties.Add(UserDefinedFieldName, Outlook.OlUserPropertyType.olYesNo, olFormatYesNoIcon)
    objProperty.Value = True
End Sub

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application

    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select

    Set objApp = Nothing
End Function

I have set a breakpoint and checked the UserProperties of the MailItem. I see that the details are there and the value is set to "True". However, the email does not show the Yes/No icon in the "Note" column of the email pane of Outlook.

How do I get Outlook to show my user defined property value in the email pane when I add the column to the view?

Upvotes: 2

Views: 2386

Answers (1)

niton
niton

Reputation: 9179

A save is required for a selection. An Inspector item prompts for a save.

Private Sub MarkHasNote_DisplayTest()

    ' Add the UserProperty column with Field Chooser
    ' You can view the value toggling when you run through the code

    Dim Selection As Selection
    Dim UserDefinedFieldName As String
    Dim objProperty As UserProperty
    Dim objItem As mailItem

    UserDefinedFieldName = "NoteTest"
    Set objItem = GetCurrentItem()
    Set objProperty = objItem.UserProperties.Add(UserDefinedFieldName, Outlook.OlUserPropertyType.olYesNo, olFormatYesNoIcon)

    objProperty.Value = Not objProperty.Value

    ' Required for an explorer selection
    objItem.Save

    ' For an inspector item there would be a prompt to save
    '  if not already done in the code

End Sub

Upvotes: 1

Related Questions