This documentation is archived and is not being maintained.

Search Object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Contains information about individual searches performed against Microsoft Outlook items. The Search object contains properties that define the type of search and the parameters of the search itself.

Using the Search object

Use the Application object's AdvancedSearch method to return a Search object. The following example returns a search object named "SubjectSearch" and displays the object's Tag and Filter property values. The Tag property is used to identify a specific search once it has completed.

Sub SearchInboxFolder()
'Searches the Inbox

    Dim objSch As Search
    Const strF As String = _
        "urn:schemas:mailheader:subject = 'Office Christmas Party'"
    Const strS As String = "Inbox"
    Const strTag As String = "SubjectSearch"
    Set objSch = Application.AdvancedSearch(Scope:=strS, _
        Filter:=strF, SearchSubFolders:=True, Tag:=strTag)

End Sub

Use the AdvancedSearchComplete event to determine when a given search has completed. The following example displays information about the search and the results of the search.

Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)

    Dim objRsts As Results
    MsgBox "The search " & SearchObject.Tag & "has completed.
    Set objRsts = SearchObject.Results
    'Print out number in Results collection
    Debug.Print objRsts.Count
    'Print out each member of Results collection
    For Each Item In objRsts
        Debug.Print Item

End Sub