WD2000: How to Use AutoText as a Result of a Form Field

ID: Q212190


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


SUMMARY

This article describes how to use AutoText as the result of a form field. The procedure uses a drop-down form field that contains an on-exit macro.


MORE INFORMATION

In the example that follows, you will create a form that contains a form field that causes a company's address to be inserted automatically when the user enters a form field and selects a company name. The address will be placed at a bookmark located in an unprotected section of the document.

Creating the On-Exit Macro

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


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

For more information about using the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
Q212536 OFF2000: How to Run Sample Code from Knowledge Base Articles


Sub DropDownAutoText1()     'This is the name of the macro
   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 

Creating 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 click the Add button. Use items (such as company names) to denote information (such as addresses) to be inserted into other places on the form.


  4. Repeat step 3 for each item needed in the Drop-Down list. Then click OK.


  5. Right-click the Drop-Down Form Field and 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 you created in the Create the On-Exit Macro section of this article. Then click OK.


Creating 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 Microsoft Word Help on the Help menu, type autotext in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Placing 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.

NOTE: This section of the document will be unprotected so that the AutoText result can be inserted into the document. Insert a Continuous Section Break above and below this bookmark. 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 will not be able to use bookmarks in headers, footers, annotations, footnotes, or endnotes because the EditGoto command in the macro will not see these bookmarks, and they cannot be unprotected in 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.


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


Protecting the Form

To protect the form, follow these steps:
  1. On the Tools menu, click Protect document, select the Forms option, and click Sections.


  2. In the Section Protection dialog box, clear the check box corresponding to the section where the AutoText will be inserted and click OK twice.


  3. Save the Form.


Additional query words: forms result module auto text

Keywords : kbmacro kbdta wd2000
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


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