Find Method

Microsoft Outlook Visual Basic

Show All

Find Method

       

Find method as it applies to the Items object.

Locates and returns an item.

expression.Find(Filter)

expression   Required. An expression that returns an Items object.

Filter   Required String. The filter of the search.

Find method as it applies to the UserProperties object.

Locates and returns a UserProperty object for the requested property name, if it exists.

expression.Find(Name, Custom)

expression   Required. An expression that returns one of the above objects.

Name  Required String. The name of the requested property.

Custom  Optional Variant. A custom string that defines the search parameters.

Example

This Visual Basic for Applications example finds a custom property named "LastDateContacted" for the contact.

Sub FindContact()
'Finds and displays last contacted info for a contact

    Dim olApp As Outlook.Application
    Dim objContact As ContactItem
    Dim objContacts As MAPIFolder
    Dim objNameSpace As NameSpace
    Dim objProperty As UserProperty

    Set olApp = CreateObject("Outlook.Application")
    Set objNameSpace = olApp.GetNamespace("MAPI")
    Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
    Set objContact = objContacts.Items.Find("[FileAs] = ""Smith, Jeff"" and [FirstName] = ""Jeff""")
    If Not TypeName(objContact) = "Nothing" Then
        Set objProperty = objContact.UserProperties.Find("LastDateContacted")
        If TypeName(objProperty) <> "Nothing" Then
            MsgBox "Last Date Contacted: " & objProperty.Value
        End If
    Else
        MsgBox "Contact not found."
    End If
End Sub