WD: How to Use AutoText as a Result of a Form Field EntryLast reviewed: March 6, 1998Article ID: Q117209 |
The information in this article applies to:
SUMMARYThis 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 INFORMATIONIn 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 MACROCreate the macro appropriate for your version of Word, 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 examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.
Word 97 for Windows or Word 98 Macintosh Edition
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 SubWARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Word 6.0 and 7.0
Sub Main ' Get result of the form field. A$ = GetFormResult$ ("DropDown1") ' UnProtect the document. ToolsUnprotectDocument ' Go to location to insert Autotext EditGoTo .Destination = "Mark1" ' Insert AutoText name chosen from dropdown list. Insert A$ ' Insert the AutoText. InsertAutoText ' Re-Protect the document. ToolsProtectDocument .NoReset = 1 End SubFor more information about the GetFormResult() function, see page 494 of the "Microsoft Word Developer's Kit" for version 6.0 and page 557 of the "Microsoft Word Developer's Kit, rev. 3."
CREATING THE DROP-DOWN FORM FIELD
Word 97 for Windows or Word 98 Macintosh EditionOpen a new document and follow these steps to create a drop-down form field:
Word 6.0/7.0Open a new document and follow these steps to create a drop-down form field:
CREATING THE AUTOTEXT ENTRIESCreate 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 additional information on creating AutoText entries, use Word Help. To locate the appropriate Help topic use the appropriate procedure for your version of Word.
Word 97 for Windows or Word 98 Macintosh EditionFollow these steps:
Word 7.x
Word 6.x
PLACING THE BOOKMARK IN THE FORMUse the appropriate procedure to insert a bookmark (in this example, name the bookmark Mark1) where you want the AutoText (address) to appear. 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.
Word 97 for Windows or Word 98 Macintosh EditionFollow these steps:
Word 6.x and 7.xFollow these steps:
PROTECTING THE FORMTo protect the form, use the following steps: 1 .On the Tools menu click Protect document, select the Forms option, and click Sections.
REFERENCES"Microsoft Word Developer's Kit," for version 6.0, pages 494 [GetFormResult() function], 681 (SetFormResult statement) "Microsoft Word User's Guide," version 6.0, pages 305-326 ("Forms"), 743- 755 ("Recording and Running Macros")
|
Additional query words: forms result module auto text
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |