expression.Included
expression Required. An expression that returns a MailMergeDataSource object.
Remarks
Use the SetAllIncludedFlags method to include or exclude all records in a mail merge data source.
Example
This example loops through the records in the mail merge data source and checks if the zip code field (in this case field number six) contains less than five digits. If a record does contain a zip code of less than five digits, the record is excluded from the mail merge and the address is marked as invalid.
Sub CheckRecords()
Dim intCount As Integer
On Error Resume Next
With ActiveDocument.MailMerge.DataSource
'Set the active record equal to the first included record
' in the data source
.ActiveRecord = wdFirstRecord
Do
intCount = intCount + 1
'Set the condition that field six must be greater than
'or equal to five
If Len(.DataFields(6).Value) < 5 Then
'Exclude the record if field six is less than five
.Included = False
'Mark the record as containing an invalid address field
.InvalidAddress = True
'Specify the comment attached to the record
'explaining why the record was excluded
'from the mail merge
.InvalidComments = "The zip code for this record " & _
"is less than five digits. It will be removed " _
& "from the mail merge process."
End If
'Move the record to the next record in the data source
.ActiveRecord = wdNextRecord
'End the loop when the counter variable equals the
'number of records in the data source
Loop Until intCount = .RecordCount
End With
End Sub