Field codes: MERGEREC field
In a merged document, the MERGEREC field displays the ordinal position of the current data record . The number reflects any sorting or filtering that you applied to the data source before the merge. You can use the MERGEREC field to number each merged document in a mail merge, in the order that you sorted the data source.
For example, if a personnel database contains 2,000 records, the values of the MERGEREC fields would range from 1 to 2,000. However, to send a form letter to employees who reached their five-year anniversary with your company, you would filter the data source, yielding a much smaller set of records, such as 500.
If you used the entire database in the merge, the MERGEREC value in a particular employee's letter could be 1,000. With the filter in effect, however, that same employee's MERGEREC value would not exceed 500.
The value of the MERGEREC field for a data record is also affected by the sort order of the data source.
For example, if you sort your mailing list alphabetically in ascending order, a name that begins with A has a low MERGEREC number. However, if you sort the same list alphabetically in descending order, the same name has a higher MERGEREC number.
Syntax
{ MERGEREC }
Note To see the field codes in a main document, press ALT+F9. To see field results again, press ALT+F9 a second time.
Example
The following example uses a MERGEREC field next to a PRINTDATE field to create unique invoice numbers. When the main document is merged with the data source, the number that results from the MERGEREC field is appended to the numbers that represent the date and time that the invoices are printed.
Invoice Number: { PRINTDATE \@ "MMddyyyyHHmm" } { MERGEREC }
For the twelfth invoice, printed at 9:46 on Feb. 13,, the document looks like this:
Invoice Number: 02132007094612
Instructions
You can use the MERGEREC field in a document or as part of a mail merge.
To use the MERGEREC field in a document
- On the
Insert
tab, in theText
group, clickQuick Parts
, and then clickField
. - In the
Field names
list, selectMergeRec
. - Click
OK
.
To use the MERGEREC field as part of a mail merge
While you are setting up the mail merge, do the following:
- On the
Mailings
tab, in theWrite & Insert Fields
group, clickRules
, and then clickMerge Record #
.