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 (macro: An action or a set of actions that you can use to automate tasks. Macros are recorded in the Visual Basic for Applications programming language.) or in another field, such as an If field.

Syntax

When you view the Set field in your document, the syntax looks like this:

{ SET Bookmark "Text" }

 Note   A field code tells the field what to show. Field results are what’s shown in the document after having evaluated the field code. To toggle between viewing the field code and the field code results, press Alt+F9.

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, do the following:

  1. On the Insert tab, in the Text group, click Quick Parts, and then click Field.
  1. In the Field names list, select Set.
  2. In the Bookmark name list, select the name of a bookmark.
  3. In the Text box, type the text that you want to assign to the bookmark.
  4. Click OK.

To use the Set field as part of a mail merge, do the following while you are setting up the mail merge:

  1. On the Mailings tab, in the Write & Insert Fields group, click Rules, and then click Set Bookmark.
  1. In the Bookmark list, select the name of a bookmark.
  2. In the Value box, type the text that you want to assign to the bookmark.

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.

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 (numeric picture switch (\#): Specifies how Microsoft Word will display the numeric result of a field. This switch is called a "picture switch" because you use symbols to show how you want the field result to look.) 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

Top of Page Top of Page

 
 
Applies to:
Word 2013, Word 2010, Word 2007