Свойство MailMergeDataSource.RecordCount (Издатель)
Возвращает значение Long , представляющее количество записей в источнике данных. Только для чтения.
Синтаксис
expression. RecordCount
Выражение Переменная, представляющая объект MailMergeDataSource .
Возвращаемое значение
Длинное целое
Пример
В этом примере почтовые индексы во присоединенном источнике данных проверяются на пять цифр. Если длина почтового индекса меньше пяти цифр, запись исключается из процесса слияния.
В этом примере предполагается, что почтовые индексы являются почтовыми индексами США. Вы можете изменить этот пример, чтобы найти почтовые индексы с 4-значным кодом указателя, добавленным в почтовый индекс, а затем исключить все записи, которые не содержат код указателя.
Sub Validate
Dim intCount As Integer
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 field six must be greater than or
'equal to five digits in length
If Len(.DataFields.Item(6).Value) < 5 Then
'Exclude the record if field six contains fewer than five 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 has " _
& "fewer than five 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
Поддержка и обратная связь
Есть вопросы или отзывы, касающиеся Office VBA или этой статьи? Руководство по другим способам получения поддержки и отправки отзывов см. в статье Поддержка Office VBA и обратная связь.