expression.Filter
expression Required. An expression that returns a Search object.
Remarks
The Filter property is set by the Filter argument when the Search object is first created.
Example
The following Microsoft Visual Basic/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
Searching String Text fields
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:
sFilter = "[CompanyName] = 'Microsoft'"
sFilter = "[CompanyName] = ""Microsoft"""
sFilter = "[CompanyName] = " & Chr(34) & "Microsoft" & Chr(34)