MailMergeDataSource.RecordCount プロパティ (Publisher)

長い データ ソース内のレコードの数を表す値を返します。 読み取り専用です。

構文

Recordcount

MailMergeDataSource オブジェクトを表す変数。

戻り値

Long

次の使用例は、添付したデータ ソースの郵便番号が 5 桁かどうかを確認します。 郵便番号が 5 桁未満の場合、そのレコードは差し込み印刷処理から除外されます。

この例では、郵便番号が米国の郵便番号であることを前提としています。 この例を変更して、郵便番号に 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 のサポートおよびフィードバックを参照してください。