Share via


ActiveRecord Property [Publisher 2003 VBA Language Reference]

Returns or sets a Long that represents the active mail merge data record. Read/write.

expression.ActiveRecord

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

Remarks

The active data record number is the position of the record in the query result produced by the current query options; as such, this number isn't necessarily the position of the record in the data source.

Example

This example validates that the value entered into the PostalCode field is ten characters long (U.S. ZIP code plus 4-digit locator code). If it isn't, it is excluded from the mail merge and marked with a comment.

Sub ValidateZip()

    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 = 1
        Do
            intCount = intCount + 1

            'Set the condition that the PostalCode field
            'must be greater than or equal to ten digits
            If Len(.DataFields.Item("PostalCode").Value) < 10 Then

                'Exclude the record if the PostalCode field
                'is less than ten digits
                .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 ten digits. It will be removed " _
                    & "from the mail merge process."

            End If

            'Move the record to the next record in the data source
            .ActiveRecord = .ActiveRecord + 1

        'End the loop when the counter variable
        'equals the number of records in the data source
        Loop Until intCount = .RecordCount
    End With

End Sub

Applies to | MailMergeDataSource Object