Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: Office FAQ

Word FAQ

Using FormFields In Word - Part 1 - Overview by fumei
Posted: 9 Jul 04 (Edited 10 Jul 04)

Word Form Fields û Part 1 - Overview

This FAQ is in two parts.  Part 1 (this one) is a general overview of Word Form Fields.  Part 2 details some specific VBA code dealing with some common tasks involving Form Fields.

What are Form Fields?

Form Fields are areas embedded in a document where the users inputs information.  It is important to understand the difference between Form Fields. ActiveX controls and VBA UserForms.   All three are areas where users input information.

Form Fields are actually parts of the document itself.  As the document author, you insert them directly into the document.  They are always visible, and their content remains with the document.

ActiveX Controls are also actual parts of the document.   As the document author, you insert them directly into the document.  They are always visible, and their content remains with the document.

You generate VBA forms by code, and therefore call them by code.  They are visible only when code makes them visible, and their content remains only as the code runs.

It sounds like FormFields and Activex Controls are the same?  Are there are differences?

Yes, but we will cover both the differences and similarities, using a FormField and a control to select from a drop down list, as an example.

Insert directly into the document
Always visible
Can set to a default item
List items can be entered manually in the document, or by code in procedures
Document must be protected
Do not have events û except for ability to run macros On Entry, and OnExit.
Do not work in PrintView
Do have a bookmark location.

ActiveX Control
Insert directly into document.
Always visible
Can set to a default item
List items can only be entered by code
Document does not have to be protected
Do have events
Do work in PrintView
Do not have a bookmark location

When should I use Form Fields?

You use Form Fields whenever you want to get some type of user input.  Unfortunately, there is a great deal of misuse of the word ôformö.  A form, from a typographical point of view, is a document that allows direct user input of information; a structure that has areas that you fill in with information.  Like an income tax form.  Generally, the purpose of forms is to restrict users to only putting in information.  Form Fields do just that.

It is my personal opinion that if you have a lot of user input, and especially if there are logical conditions between those inputs, it is better to use a UserForm.  For one thing, you can do error trapping on the fly, as they move between fields.

Creating a UserForm, however, is more involved than using simple Form Fields in the document.  You certainly can do error trapping on Form Fields, but generally, this occurs afterwards.

If you have a document with up to 20 separate pieces of user input, use FormFields.  More than that is possible (technically there is no limit), but a specifically designed UserForm may be a better solution.  For the purposes of this FAQ, the assumption is you are going to use Form Fields.

What kind of user input can I get?

There are three (3) types of information the user can input, using Form Fields.  These are:  text that the user types in, Boolean (True or False) choices, and choosing an item from a list.

TextInput û these are areas where the user can input any text.  This text can be numbers û as text - like ô25ö.  If you need to use actual numbers, you can change the type of default input.  See ôCan I set up default values for FormFields?ö

CheckBox û these are little boxes that the user can either make checked (True), or not (False).  They can toggle between either state.

DropDown û these are the commonly seen Windows dropdown lists.  The user can select from the list.  The list normally is created at design time (when you create the dropdown, you populate the list), but may also be created dynamically.  For example, the result of a checkbox could repopulate a dropdown list.

How do I get Form Fields into my document?

Insert Form Fields with the Forms Toolbar.  Normally this is not visible.  To see the toolbar, select View > Toolbars, and then select Forms.  The default order on the toolbar (from left to right) is Text Form Field, Checkbox Form Field, Drop Down Form Field.  The button to the right of that is the Form Field Options.

Clicking a button inserts that type of FormField, at the cursor location in the document.

Can I set up default properties and values for FormFields?

Yes.  If you know what they are, it is best to set up defaults as soon as you insert the FormField.  After inserting the FormField, click the Option button on the Forms toolbar.  The Options dialog will display according to the type of FormField.

You can also get to the Options by placing the cursor immediately to the left, or right, of the FormField, and clicking the Options button.  This also works with the cursor in the FormField.  If the Forms toolbar is not visible, with the cursor in the FormField, right click and select Properties

Text FormField properties.

Type of input - this can be set for text, numbers, dates, current date, or as calculations.
Default text û text will be displayed in the FormField.  You can allow changes, or not.  If you do not want to allow changes, uncheck ôFill-in enabledö
Maximum length û you can restrict the amount of text the user can input.  There is no message.  It simply does not allow any more than the length (including spaces) set here.
Text format û upper case, lower case, Title, first capital

Checkbox properties

Default - - whether the box shows as checked or unchecked
Size û auto sized, or exact size
Enabled û yes or no

Drop Down Properties

Here is where you add the items to a drop down list.  Type the item in the Drop Down item field, and press Enter, or click Add.  You may move items up or down, to fit the order you want.  It is a good idea to add a leading space to item, as they appear better in the drop down.

All FormField types have the ability to run macros, either on Entry, or on Exit.  See ôCan I run macros with FormFields?ö

Can I run macros with FormFields?

Yes.  This is a very powerful feature of FormFields.  An On Entry macro, for example, could reset the properties of the FormField itself.  It could check the result (a name perhaps) from a previous FormField, and reset its default text to that name.  A certain name could reset the next check box to UnChecked, and disable allowing changes.  You may want to have a particular input skip the next FormField.  There is a multitude of possibilities.

Part 2 of this FAQ contains sample code covering these scenarios.

Can I put FormFields anywhere in a document?

Sort of.  There is no restriction on where you put FormFields.  There is a restriction on how you place them.

Important!  Form fields only work in protected sections.  It is important to distinguish protecting a document, from protecting a section.  Sections, in Word, are coded breaks in the document.  They can be defined as breaking to a new page (odd, even etc), or continuous.  Continuous means there is a new section, and that new section starts immediately.

Example:  This is on one page.

Text1 text1 text1 text1 text1 text1
    [Section break]

Text2 text2 text2 text2 text2 text2 text2 text2 text2 text2 text2 text2 text2
    [Section break]

Text3 text3 text3 text3 text3 text3 text3 text3 te

The area with ôtext2ö is a separate section from the other areas.  Protecting it is different from protecting the document, which essentially adds a password to opening the file.  Once protected no change in content, or format are permitted.  Even selecting the content fails.  The only exception is the use of FormFields.  This is the purpose of protecting sections (well it also works for tracking changes, and comments).  A user may only enter, or change, information only in FormFields.

The area marked as a section can be as small as a single word.  Actually it can be as small as a single character.

When designing a document that will use FormFields it is crucial to plan ahead.  Do you want the user to be able to edit the document?  They can always edit the FormFields, but what about editing other text?  If user editing is permitted, those parts need to be in unprotected sections.

You can make section breaks wherever you like.

The following is on ONE line.

Do you use Windows?  Yes  [section break] {Checkbox FormField}[section break]  No[section break] {Checkbox FormField}[section break]  

Protecting the sections containing the checkboxes allows any editing of the text ôDo you use Windows?  Yesö, as well as the text, ôNoö.  However, practically speaking, unless there is a need to allow user changes, it makes more sense to have fewer section breaks.

[section break] Do you use Windows?  Yes   {Checkbox FormField}  .No   {Checkbox FormField}[section break]    There is no real need to allow users to edit the question û so protect the whole line.

Placing FormFields takes consideration of precisely what the user needs to do with the document.

How does someone use FormFields?

Once protected for forms, when someone opens the file one of two things happens.  If the entire document is protected for forms û in other words, there is NO user editing permitted û the cursor jumps automatically to the first FormField.

With an unprotected first section, the cursor goes to the start of the document, as normal.  To enter information the user clicks on a FormField.  The Tab key moves the cursor from FormField to FormField.  Note that they do NOT have to start with the first FormField.  While the user has the document open, all FormFields (if properly protected) are available to them, in any order they like.  They may also jump back and forth, changing the FormField values, as much as they like.

What is a good design for a document that uses FormFields?

As the reason for FormFields is to gather user input, good design is a document that does not require the user to edit the document itself.  Form fields are generally a tool for fast data entry.  Good design has all text coming from the user within a text FormField.

In which case, simply keep the document as one section, and protect that.  The user cannot change anything, except their input, which seems fair.

Do FormFields print?

Yes  Text FormFields have the entire content visible.  The size of the FormField expands to match the text inside it.  Checkbox FormFields show as checked, or not.  Drop down FormFields show the item that is selected.  If the user has not changed the drop down, the first item shows.

How do I get information from the FormFields?

The information in FormFields is visible information.  However, it is also available to use programmatically, using code.  Please see ôUsing FormFields in Word Part 2 û ôCoding with Form Fieldsö

Back to Microsoft: Office FAQ Index
Back to Microsoft: Office Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close