Word Fields

Home Up Odds & Ends Photo Gallery Search Contact Me

 

 

The information in this website is provided without risk or obligation and free of charge.  However, if you have benefitted from my efforts here and would like to make a contribution to help me continue and maintain this work then any donation will be greatly appreciated. Please click the adjacent button to access PayPal.  Thank you.
 
Word includes an incredibly versatile capability to insert specialized data  in your documents by using fields.  Just click on the menu item Insert>Fields for a listing of most of the fields available in Word.  This Microsoft Word Help & Tips Page will show you a few simple methods for inserting fields in your documents and some methods for updating and working with field code. 
There are three simple user interface methods for inserting fields in your document.
  • The Insert>Field menu interface
  • Pre-Defined AutoText entries
  • Direct entry using function keys and the keyboard

To illustrate each of these methods we will use a pair of Word fields in the document footer  to display the page number of a larger collection of total pages .  Example:

This display is constructed using plain text and two Word fields.  The fields used are the "Page" and "NumPages" fields.

Tip:  Use ALT+F9 any time you want to toggle between the underlying field code and the result.

1.  You can use the Insert>Field menu interface for this construction with four easy steps:

     a. Center justify in the footer pane and type the text  - "Page "
     b. Use the Insert>Field menu and to insert a Page field
     c. Type - " of "
     d. Use the Insert>Field menu to insert a NumPage field
     e. Type - " pages"

2.  Word has included several pre-defined AutoText entries that use Word fields.  The Page X of Y data can be quickly inserted using the AutoText entry provided for this purpose.  As shown in the illustration, the Insert AutoText menu is located on the Header and Footer toolbar.

3.  For most field entries I prefer the direct entry method using the function keys and keyboard.  While this method may not be the most efficient in this case, knowing how to do it will allow you to enter many complex or nested fields that can not be entered using the methods previously described.

    - The field delimiters { and } that you see when field code is displayed are not the ordinatary brace symbols located on the keyboard (on the two keys to the right of "P").  The field code delimiters are entered by pressing CTRL+F9.  Go ahead and try it.  Press CTRL+F9 in your document and observe the delimiter pair that is created.   Type a space and enter another delimiter pair.  Now put the IP inside the first pair and type in Page.  Type Numpages in the second pair.  Relocate the IP as necessary to complete the plain text. 

     - Now go back and fill in the field names inside the delimiters

 - Finally toggle the display with ALT+F9

   

TIP: An alternative method is first type the text and field names, select the field name and press CTRL+F9 and repeat for the other fields.

     - The direct entry method is especially useful for constructing complex or nested fields.  Consider the following nested IF field used to evaluate and display information about a student:

     - Here the IF fields are nested like Chinese eggs.  While this construction can be performed with the menu interface, with practice it is much easier to simply press CTRL+F9 three times to create the nested fields and then fill in the data with the keyboard.

Updating Fields.  Remember that Word is a word processor and not a spreadsheet.  Unlike Excel and other spreadsheet applications, most fields used in Word will not be updated automatically simply by changing a varialbe.  In fact, some fields don't update at all without specific user action.  For more on field update behavior see the Microsoft Knowledge Base Article 21169:

Which fields are updated when you open, repaginate, or print document

Lets look at a simple formula field for summing the results of cell A1 and A2 in a table: 

The field code Display after updating the field result Display after changing one of the variables before the field is updated

In simple Word documents after a variable is changed a user action is usually required in order of fields to be updated and display accurate results .  There are several methods that users may employ to update fields.

  • Update fields individually by mouse right clicking on the field and selecting "update field"
  • Update fields individually by selecting the field and pressing F9  
  • Update fields globally by selecting all text (including fields) with (CTRL+a) and pressing F9
  • Update fields globally at print execution using the user preference File>Print>Options> Printing Options>Update Fields
  • Update fields globally by shifting to and from "Print Preview."  (File>PrintPreview)
    Note: Print options must be set to update fields
  • Update fields with a macro.  A macro for updating fields in a document is provided below

Sub UpdateFields()
Dim rngStory As Word.Range
Dim oShp As Word.Shape
For Each rngStory In ActiveDocument.StoryRanges
    Do
        On Error Resume Next
        rngStory.Fields.Update
        Select Case rngStory.StoryType
            Case 6, 7, 8, 9, 10, 11
                If rngStory.ShapeRange.Count > 0 Then
                    For Each oShp In rngStory.ShapeRange
                        If oShp.TextFrame.HasText Then
                            oShp.TextFrame.TextRange.Fields.Update
                        End If
                    Next oShp
                End If
            Case Else
                'Do Nothing
        End Select
        On Error GoTo 0
        'Get next linked story (if any)
        Set rngStory = rngStory.NextStoryRange
    Loop Until rngStory Is Nothing
Next rngStory
End Sub

:old:Bonus Tip:  For a more extensive treatment of macros dealing with the field collection, see:  Field Macos.

Unlinking fields.  Sometimes users wish to enter data based on a field value and then break the link with that value.  A good example and common source of frustration is the { DATE } field that is inserted by default whenever the menu option Insert>Date and Time is used.  Go ahead and try it.  Click Insert>Date and Time and select a format (Note:  for my example I am using the format "MMMM, d, yyyy").  Now toggle the field code (ALT+F9).  The result shown below is a field code based on the system date.

    - { Date } fields are one of several Word fields that will update automatically when the document is opened.  If you save and close your practice document and open it next week or next year or next century, the displayed date will automatically update to the system date on that date!!  A nightmare and great source of frustration as most users that want a dated document want that date to remain fixed.  

    - When you generate data based on a field code like the { Date } field, you can break the link with the field value and convert the result to plain text by selecting the field and pressing the keyboard command CTRL+SHIFT+F9.   

:old:Bonus Tip:  An alternative method for inserting the current date  (and making it stick) is to uncheck "Update automatically" in the Insert Date and Time dialog box.  This results in a plain text date stamp being inserted instead of a { Date } field or you can insert a  { CreateDate } field.
There are countless examples and applications for using Word field code.  For more on special formatting in Word fields see fellow MVP Graham Mayor's Special Formats for Word Fields

Looking for something else?

Google