Свойство MailMergeDataSource.ActiveRecord (Publisher)
Возвращает или задает значение Long , представляющее активную запись слияния. Для чтения и записи.
Синтаксис
expression. ActiveRecord
Выражение Переменная, представляющая объект MailMergeDataSource .
Возвращаемое значение
Длинное целое
Замечания
Номер активной записи — это позиция записи в результате запроса, созданном текущими параметрами запроса; Таким образом, это число не обязательно является положением записи в источнике данных.
Пример
В этом примере проверяется, что значение, введенное в поле Почтовый индекс, составляет десять символов (почтовый индекс США плюс 4-значный код указателя). Если это не так, он исключается из слияния и помечается примечанием.
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
Поддержка и обратная связь
Есть вопросы или отзывы, касающиеся Office VBA или этой статьи? Руководство по другим способам получения поддержки и отправки отзывов см. в статье Поддержка Office VBA и обратная связь.