InvalidComments Property

Microsoft Word Visual Basic

InvalidComments Property

       

If the InvalidAddress property is True, returns or sets a String that describes an invalid address error. Read/write.

expression.InvalidComments

expression   Required. An expression that returns one of the objects in the Applies To list.

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 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, the address is marked as invalid, and a comment why the record was excluded.

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" & _
                    "is less than five digits. This record is" & _
                    "removed from the mail merge process."
            End If

            .ActiveRecord = wdNextRecord
        Loop Until intCount >= .ActiveRecord
    End With

End Sub