Microsoft KB Archive/196939

= WD97: How to Create a Form That Updates Automatically =

Article ID: 196939

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Word 97 Standard Edition

-



This article was previously published under Q196939





SUMMARY
In Microsoft Word, you can create a form in which information is inserted automatically, based on information that you type or select from a form field.

For example, if you want to select a company from a list of company names, and you want that company's address to appear in another area of your form, you can set up your form by using a drop-down form field, AutoText entries, a bookmark, and an on-exit macro.

This article demonstrates how to create a form that contains a form field that causes a company's address (which is stored as an AutoText entry) to be inserted automatically when you select the company name from a drop-down list. The form then moves to the next form field.



MORE INFORMATION
In the example that follows, you create a form that contains a form field that inserts a company's address automatically when you quit a form field after you select a company name. The address is placed at a bookmark that is located in the protected section of the document.

How to Create the On-Exit Macro
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

173707 OFF97: How to Run Sample Code from Knowledge Base Articles

Create the macro, where DropDown1 is the bookmark that represents the drop-down form field that contains your list of items, and Mark1 is the bookmark that represents where you want the AutoText inserted. Sub DropDownAutoText1

Dim DropResult As String

' Get result of the form field. DropResult = ActiveDocument.FormFields("DropDown1").Result

' UnProtect the document. ActiveDocument.UnProtect

With Selection

' Go to location to insert Autotext .GoTo What:=wdGoToBookmark, Name:="Mark1"

' Insert AutoText name chosen from dropdown list. .InsertAfter DropResult

' Insert the AutoText. .Range.InsertAutoText

End With

' Re-Protect the document. If ActiveDocument.ProtectionType = wdNoProtection Then ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If

End Sub

How to Create the Drop-Down Form Field
Open a new document, and follow these steps to create a drop-down form field:
 * 1) On the View menu, point to Toolbars, and then click Forms.
 * 2) On the Forms toolbar, click Drop-Down Form Field (the third button).
 * 3) Double-click the newly inserted form field. Enter an item name in the Drop-down Item box, and select the Add button. Use items (such as company names) to denote information (such as addresses) that is to be inserted into other places on the form.
 * 4) Repeat step 3 for each item you need in the drop-down list. Then click OK.
 * 5) Right-click the drop-down form field, and then click Properties on the shortcut menu.
 * 6) In the Drop-Down Form Field Options dialog box, under Run macro on, in the Exit box, select the macro that you created in the "How to Create the On-Exit Macro" section of this article. Click OK.

How to Create the AutoText Entries
Create the AutoText entries. Give each AutoText entry the same name that is used in the drop-down form field list. The content of the AutoText entry will be the company address.

For more information about creating AutoText entries, click Contents and Index on the Help menu, click the Index tab in Microsoft Word Help, type the following text

autotext, creating

and then double-click the selected text to go to the "Create an AutoText entry to store and reuse text and graphics" topic. If you are unable to find the information you need, ask the Office Assistant.

How to Place the Bookmark in the Form
Use the following procedure to insert a bookmark (in this example, name the bookmark Mark1) where you want the AutoText (address) to appear. To insert a bookmark, follow these steps:
 * 1) On the Insert menu, click Bookmark.
 * 2) Type Mark1 on the Bookmark name line.
 * 3) Click Add.

NOTE: You cannot use bookmarks in headers, footers, annotations, footnotes, or endnotes, because the EditGoto command in the macro does not see these bookmarks, and they cannot be unprotected in your form.

ADDITIONAL INFORMATION: If you want the bookmark to be in an unprotected section, insert a continuous section break above and below the bookmark. When you place the bookmark in an unprotected section, you can change the text that is inserted at the bookmark, without changing the associated form field that inserted the text, or without unprotecting your form.

To insert a continuous section break, follow these steps:
 * 1) Move the insertion point either above or below the bookmark.
 * 2) On the Insert menu, click Break.
 * 3) In the Break dialog box, click to select Continuous.
 * 4) Click OK.

Repeat these steps as needed to place a continuous section break above and below your bookmark.

How to Protect the Form
To protect the form, follow these steps:  On the Tools menu, click Protect document. In the Protect Document dialog box, click to select Forms.

NOTE: If you inserted continuous section breaks in your form, and you want to protect certain sections of the form and leave other sections unprotected, follow these steps:  In the Protect Document dialog box, click Sections. In the Section Protection dialog box, click to clear the section or sections that you do not want protected. Click OK to close the Section Protection dialog box. </li> Click OK to close the Protect Document dialog box.</li> Save and close your form.</li></ol>

Additional query words: forms result module auto text

Keywords: kbinfo kbmacro KB196939

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.