MailMergeDataSource.InvalidAddress property (Word)

True for Microsoft Word to mark a record in a mail merge data source if it contains invalid data in an address field. Read/write Boolean.

Syntax

expression. InvalidAddress

expression An expression that returns a 'MailMergeDataSource' object.

Remarks

Use the SetAllErrorFlags method to set both the InvalidAddress and InvalidComments properties for all records in a data source.

Example

This example loops through the records in the mail merge data source and checks whether 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 ExcludeRecords() 
 
 Dim intCount As Integer 
 
 On Error Resume Next 
 
 With ActiveDocument.MailMerge.DataSource 
 .ActiveRecord = wdFirstRecord 
 Do 
 intCount = intCount + 1 
 'Counts the number of digits in the postal code field and if 
 'it is less than 5, the record is excluded from the mail merge, 
 'marked as having an invalid address, and given a comment 
 'describing why the postal code was removed 
 If Len(.DataFields(6).Value) < 5 Then 
 .Included = False 
 .InvalidAddress = True 
 .InvalidComments = "The ZIP Code for this record" & _ 
 "has fewer than five digits. It will be" & _ 
 "removed from the mail merge process." 
 End If 
 
 .ActiveRecord = wdNextRecord 
 Loop Until intCount >= .ActiveRecord 
 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.