MailMergeFilters Collection

Microsoft Publisher Visual Basic

Show All Show All

MailMergeFilters Collection

MailMergeDataSource MailMergeFilters

Represents all the filters to apply to the data source attached to the mail merge or catalog merge publication. The MailMergeFilters object is comprised of MailMergeFilterCriterion objects.

Using the MailMergeFilters object

Use the Add method of the MailMergeFilters object to add a new filter criterion to the query. This example adds a new line to the query string and then applies the combined filter to the data source. This example assumes that a data source is attached to the active publication.

Sub FilterDataSource()
    With ActiveDocument.MailMerge.DataSource
        .Filters.Add Column:="Region", _
            Comparison:=msoFilterComparisonIsBlank, _
            Conjunction:=msoFilterConjunctionAnd
        .ApplyFilter
    End With
End Sub
		

Use the Item method to access an individual filter criterion. This example loops through all the filter criterion and if it finds one with a value of "Region", changes it to remove from the mail merge all records that are not equal to "WA". This example assumes that a data source is attached to the active publication.

Sub SetQueryCriterion()
    Dim intItem As Integer
    With ActiveDocument.MailMerge.DataSource.Filters
        For intItem = 1 To .Count
            With .Item(intItem)
                If .Column = "Region" Then
                    .Comparison = msoFilterComparisonNotEqual
                    .CompareTo = "WA"
                    If .Conjunction = "Or" Then .Conjunction = "And"
                End If
            End With
        Next
    End With
End Sub