Search.Filter Property (Outlook)
Returns a String value that represents the DASL statement used to restrict the search to a specified subset of data. Read-only
When searching Text fields, you can use either an apostrophe (') or double quotation marks ("") to delimit the values that are part of the filter. For example, all of the following lines function correctly when the field is of type String:
The following Microsoft Visual Basic for Applications (VBA) example creates a new Search object. The event subroutine fires after the search has finished and displays the Tag and Filter properties of the Search object in addition to the results of the search.
Sub SearchInboxFolder() 'Searches the Inbox folder Dim objSch As Outlook.Search Const strF As String = _ "urn:schemas:mailheader:subject = 'Office Holiday Party'" Const strS As String = "Inbox" Const strTag As String = "SubjectSearch" Set objSch = _ Application.AdvancedSearch(Scope:=strS, Filter:=strF, Tag:=strTag) End Sub
Use an AdvancedSearchComplete event subroutine to ensure the integrity of the data stored in the Search object.
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search) Dim objRsts As Outlook.Results Dim Item as Outlook.MailItem MsgBox "The search " & SearchObject.Tag & "has finished. The filter used was " & _ SearchObject.Filter & "." Set objRsts = SearchObject.Results 'Print out number in results collection MsgBox objRsts.Count 'Print out each member of results collection For Each Item In objRsts MsgBox Item Next End Sub