WD2000: How to Update Fields in a Protected Form

ID: Q212356


The information in this article applies to:
  • Microsoft Word 2000


SUMMARY

Fields in a document protected for forms may not be updated when you fill out the form. This article describes four methods you can use to update regular fields or to automatically insert and update the result of one form field into another area of a form.


MORE INFORMATION

Method 1: Use the "Calculate On Exit" Option

In Word 2000, form fields include a Calculate on exit option. When you turn on this option, fields and form fields can be updated in a protected form document.

Fields not updated by this switch include:
TOC
PAGE
INDEX
PAGEREF
For additional information, please see the following article in the Microsoft Knowledge Base:
Q212244 WD2000: How to Use Calculate on Exit in a Forms Document

Method 2: Use a Macro

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
The following example macro multiplies the "Unit Price" form field by the "Units Ordered" form field and places the result in the "SubTotal1" form field. The macro must be set as an on-exit macro for both the "Unit Price" and "Units Ordered" form fields.


Sub OnExitMacroExample()
   With ActiveDocument
      .FormFields("SubTotal1").Result = _
         Val(.FormFields("UnitPrice").Result) * _
            Val(.FormFields("UnitsOrdered").Result)
   End With
End Sub 
NOTE: For each field that receives the information automatically, clear the Fill-In Enabled check box in the Text Form Field Options dialog box. This minimizes the chance of accidentally modifying the field result.

Method 3: Reference a Form Field Entry Elsewhere in a Document

There may be times that you may want to reference a form field entry elsewhere in a document.

To repeat a form field entry using a reference field, follow these steps:
  1. Position the insertion point where you want the data to be repeated.


  2. NOTE: The document (or section where the insertion point is) must be unprotected to insert a field.
  3. On the Insert menu, click Field and select REF from the Field Name list.


  4. In the Field Code box, insert the form field bookmark name (for example, text1) that represents the form field into which you are entering the data.


  5. Click OK.


The REF field must be updated to display and print the text. An update includes all fields such as DATE and TIME. There are two ways to update fields in the protected area of your form:

  • If the form is to be a printed form, you can have the REF fields update when you print the document.

    To update fields when printing:

    1. On the Tools menu, click Options.


    2. On the Print tab, click to select the Update Fields check box.


    When you select this option, fields may not be updated on the screen, but Word updates them properly when you print the document.


  • If you need all fields to be updated on the screen as you fill out the form, including fields not updated using the Calculate on exit option as described in Method 1, use the following macro as the On exit macro for your form field(s):

    NOTE: Running the following macro updates all fields in the entire document, including linked objects (for example, a linked Microsoft Excel spreadsheet).
    
    Sub UpdateAllFields()
       Dim aStory As Range
       Dim aField As Field
       For Each aStory In ActiveDocument.StoryRanges
          For Each aField In aStory.Fields
             aField.Update
          Next aField
       Next aStory
    End Sub 


NOTE: Because this exit macro may cause a slight delay on some computers, you may choose to select the Update Fields on printing option if this is to be a printed form. You may also choose to select the Calculate on exit option as described in Method 1.

Additional query words: forms formfield ref unprotect vba

Keywords : kbdta kbmacroexample kbfield kbform wd2000
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: July 23, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.