Field codes: SET field
The SET field assigns specific information to a named variable, called a bookmark. For the information to appear in the document, you must insert a REF field that refers to the bookmark. You can also use the bookmark to process the information invisibly, such as in a macro or in another field, such as an IF field.
Syntax
{ SET Bookmark "Text" }
Note To see the field codes in a main document, press ALT+F9. To see field results again, press ALT+F9 a second time.
Properties
- Bookmark
The name that stands for the information: a variable - for example, InterestRate.
- "Text"
Information that is assigned to the bookmark: a literal value. Enclose text in quotation marks; numbers don't require quotation marks. The information can be the result of a nested field.
- "Text"
Example
In the following example, a document contains the bookmarks EnteredBy, UnitCost, Quantity, SalesTax, and TotalCost. SET fields establish the contents of each of these bookmarks, and REF fields have been inserted in the document to display the contents of the bookmarks. A numeric picture switch displays the UnitCost and TotalCost values with a currency symbol and two decimal places.
{ SET EnteredBy "Yury Vronsky" }
{ SET UnitCost 25 }
{ SET Quantity { FILLIN "Enter number of items ordered:" } }
{ SET SalesTax 10% }
{ SET TotalCost { = (UnitCost * Quantity) + ((UnitCost * Quantity) * SalesTax) } }
This confirms your order of our book. You ordered { REF Quantity } copies at { REF UnitCost \# "$#0.00" } apiece. Including sales tax, the total comes to { REF TotalCost \# "$#0.00" }
Thank you for your order,
{ EnteredBy }
If the user types 3 in response to the prompt for the FILLIN field, the resulting document looks like this:
This confirms your order of our book. You ordered 3 copies at $25.00 apiece. Including sales tax, the total comes to $82.50.
Thank you for your order,
Yury Vronsky
Instructions
You can use the SET field in a document or as part of a mail merge.
To use the SET field in a document
- On the
Insert
tab, in theText
group, clickQuick Parts
, and then clickField
. - In the
Field names
list, selectSet
. - In the
Bookmark name
list, select the name of a bookmark. - In the
Text
box, type the text that you want to assign to the bookmark. - Click
OK
.
To use the SET 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 clickSet Bookmark
. - In the
Bookmark
list, select the name of a bookmark. - In the
Value
box, type the text that you want to assign to the bookmark.