Unfortunately there is no field that returns this value.
In the general case you can't even use a SQL query (e.g. in a DATABASE
field) to return the count, because in addition to any query that Word
generates, the user can select/deselect individual records.
You can however, get the count using VBA, e.g.
Function MyRecordCount() As Long
Dim lngRecordCount as Long
Dim lngFirstRecord As Long
Dim lngLastRecord As Long
Dim lngRecord As Long
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord ' the last
selected record
lngLastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
' Get the first record, selected or not.
' If there are no selected records, this fails
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstDataSourceRecord
lngFirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
lngRecordCount = 0
For lngRecord = lngFirstRecord To lngLastRecord
If ActiveDocument.MailMerge.DataSource.Included Then
lngRecordCount = lngRecordCount + 1
End If
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextDataSourceRecord
Next
MyRecordCount = lngRecordCount
End Function
You can then insert that in your document or use it (for example) to set a
Document Variable called RecordCount
that you can insert using a { DOCVARIABLE RecordCount } field.
Peter Jamieson