MailMergeDataSource.Included property (Word)

True if a record is included in a mail merge. Read/write Boolean.

Syntax

expression. Included

expression 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 fewer than five digits. If a record does contain a ZIP Code of fewer 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 " & _ 
 "has fewer 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

See also

MailMergeDataSource Object

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.