This example searches the records to verify that the length of the PostalCode field for each record is at least five digits long. If it is not, the record is excluded from the mail merge and flagged as invalid.
Visual Basic for Applications
Dim intRecord As Integer
For intRecord = 1 To .DataSource.RecordCount
.DataSource.ActiveRecord = intRecord
If Len(.DataSource.DataFields("PostalCode").Value) < 5 Then
.Included = False
.InvalidAddress = True
.InvalidComments = "This record is removed " & _
"from the mail merge because its postal code" & _
"has less than five digits."