OfficeDataSourceObject.ApplyFilter method (Office)
Applies a filter to a mail merge data source to filter specified records meeting specified criteria.
Syntax
expression.ApplyFilter
expression A variable that represents an OfficeDataSourceObject object.
Example
This example adds a new filter that removes all records with a blank Region field and then applies the filter to the active publication.
Sub OfficeFilters()
Dim appOffice As OfficeDataSourceObject
Dim appFilters As ODSOFilters
Set appOffice = Application.OfficeDataSourceObject
appOffice.Open bstrConnect:="DRIVER=SQL Server;SERVER=ServerName;" & _
"UID=user;PWD=;DATABASE=Northwind", bstrTable:="Employees"
Set appFilters = appOffice.Filters
MsgBox appOffice.RowCount
appFilters.Add Column:="Region", Comparison:=msoFilterComparisonEqual, _
Conjunction:=msoFilterConjunctionAnd, bstrCompareTo:="WA"
appOffice.ApplyFilter
MsgBox appOffice.RowCount
End Sub
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for