Export (0) Print
Expand All

How to: Read Data from a Custom Field of an Item

This example reads data from a custom field of a contact item. This example checks contacts in a folder named Picnic for a value in a custom text field named Picnic. The code displays the name of all contacts that have the value Potato Salad.

Applies to: The information in this topic applies to application-level projects for Outlook 2007 and Outlook 2010. For more information, see Features Available by Office Application and Project Type.

Private Sub ThisAddIn_Startup(ByVal sender As Object, _
 ByVal e As System.EventArgs) Handles Me.Startup
    Dim result As New System.Text.StringBuilder()
    Dim contactFolder As Outlook.MAPIFolder = Me.Application.GetNamespace _
        ("MAPI").GetDefaultFolder _
        (Outlook.OlDefaultFolders.olFolderContacts). _

    Dim picnicMembers As Outlook.Items = _
        contactFolder.Items.Restrict("[Picnic]='Potato Salad'")

    For Each contact As Outlook.ContactItem In picnicMembers

    If result.Length > 0 Then
        MsgBox(result.ToString(), "Potato Salad")
        MsgBox( _
            "No contacts are assigned potato salad for the picnic.", _
            "Potato Salad")
    End If
End Sub

A COMException exception is thrown if the custom contact folder Picnic is not found in the folders collection. You can catch this exception and create the folder if it is missing.

Community Additions

© 2015 Microsoft