COMMENTS AND REVISION MARKS

FORMS

Prevent a User from Accessing Parts of a Document

The Annoyance:

Our office is moving from paper-based forms to online forms as part of our "Drive to Save the World." I've created online versions of most of the forms now, with plenty of space for people to fill in the relevant information. The trouble is, they tend to delete areas of the form that they think don't apply to them.

The Fix:

What you need is a Word form: a document that has fields for filling in information, and in which you can protect the areas that you don't want users to change.

To create a form, follow these general steps:

  1. Create a document as usual, entering the necessary text, leaving gaps for the form fields that the users will fill in, and formatting the contents as needed.


    Tip: You can also create a form in a template rather than in a document and then make it available to your colleagues in a workgroup templates folder shared on the network. However, a document kept on the network is usually easier to keep updated than a template. Chapter 2 discusses how to create templates.
  2. Right-click the menu bar or any displayed toolbar and choose Forms from the pop-up menu to display the Forms toolbar (or choose View Toolbars Forms).

  3. Options, click the View tab, and check the Bookmarks box.) You can toggle field shading on and off by clicking the Form Field Shading button on the toolbar. Having the shading displayed while youre laying out the form helps you avoid deleting form fields by accident .
  4. Double-click a form field (or select the field and click the Form Field Options button on the toolbar) to display the Form Field Options dialog box for the form field. Figure 5-1 shows the Text Form Field Options dialog box; the Check Box Form Field Options dialog box and the Drop-Down Field Options dialog box include checkbox- and drop-down-specific options but are otherwise almost identical. They include similar fields for running a macro on entry to and exit from the form field, the bookmark name for the field, a checkbox for specifying whether the field is enabled, and a checkbox for controlling whether Word calculates the field when the user leaves it.


    Tip: You can add help text to a form field by clicking the Add Help Text button and working in the Form Field Help Text dialog box. You can choose between two forms of help text: text displayed in the status bar when the user accesses the field, and text displayed when the user presses F1 when the field is selected. This help can be useful for complex forms, but you should try to explain the contents of fields in the body of the form so that users don't need to rely on the help text, which they may not be savvy enough to access.
  5. To test your form, click the Protect Form button (the button with the lock icon) on the Forms toolbar. Word then makes only the form fields accessible. You can move the selection from one field to another by pressing Tab, Page Down, or to move forward, or Shift+Tab, Page Up, or to move backward. Click the Protect Form button again to remove the protection.

  6. Protect Document. In Word 2003, check the "Allow only this type of editing in the document box in the Protect Document task pane; choose "Filling in forms" in the drop-down list; click the Yes, Start Enforcing Protection button; and enter a password in the Start Enforcing Protection dialog box. In Word XP or Word 2000, select the Forms option in the Protect Document dialog box, type a password, and click the OK button.
    Figure 5-1. Use the Form Field Options dialog box to control whether the form field is enabled (so that the user can fill it in) and to set the name of the bookmark that refers to it. The other options available depend on the type of form field: a text box (as shown here), a checkbox, or a drop-down list.

  7. Save the document, and then make it available to the users who need to fill in the form. When a user opens the form, she can move quickly from one field to another, fill in the necessary information, and save the form under a name other than its current name (because the form is password-protected).


Tip: Word uses the term "form" to describe a document (or template) with areas that you fill in, but there's no reason to restrict your use of Word forms to documents that are considered to be forms in the conventional sense of the word. Word's form capabilities can be useful for many other sorts of documents, from business invoices to personal letters .

Force a User to Fill In Certain Fields

The Annoyance:

Right, protecting the form has prevented my colleagues from deleting the sections that don't apply to them. But they're still leaving some vital fields blank and filling in others incorrectly.

The Fix:

For a text form field, you can control what the user enters to some extent by specifying the type of text ("Regular text," "Number," "Date," "Current date," "Current time," or "Calculation") in the Type drop-down list in the Text Form Field Options dialog box. You can also control the default entry, the length of the entry, and the format in which it is entered.

For any form field, you can run a macro on entry (when the user moves the selection to the form field), on exit (when the user moves the selection to another form field), or both. An exit macro is especially useful for checking that the contents of the field are suitable and for displaying a message box explaining any problems to the user. (Chapter 8 discusses how to create macros.)

Exit macros are almost ideal for ensuring that the user fills in all the required fields in the formbut only almost. If the user uses the keyboard to move from field to field, the exit macros can validate each field. But if the user moves about the form with the mouse, he can skip fields altogether. When the user skips a field, the exit macro doesn't run, and there's no validation.

A straightforward approach is to force the user to work through the fields in the form in turn , validating the result of each field as the user leaves it. This approach has the advantage of alerting the user immediately to a problem with a field, but it means the user must work through the fields in order.

To validate each field as the user leaves it, create an exit macro for each field. Perform suitable validation (for example, check the Result property of a text FormField object to make sure that it's not an empty string) and display a message box explaining any problems that the user must fix before leaving the field. For each field except the last, make the exit macro, after finding the field's contents satisfactory, select the next form field (e.g., ActiveDocument.FormFields("FullName").Select selects the field with the bookmark name FullName ). The user can then fill in the next field. If the user tries to leave a field without completing it, the exit macro runs and tells him the problem.

If you're reluctant to constrict users to working through the form in order, validate the form's contents when the user submits it or saves it. If you add a Submit button from the Control Toolbox (choose View Toolbars Control Toolbox), you can attach to it a macro that performs the validation and notifies the user of any fields that were left blank. If you rely on the user saving the form, either create a macro named FileSave in the form that performs the validation, identifies any problems, and saves the form if all is well; or use the DocumentBeforeSave event to perform the validation.

Capture Only the Data from a Form

The Annoyance:

Okay, I've got my colleagues filling in the form nowand they're filling in all the fields more or less correctly, which is great. The problem is, I need to extract the data from the form and dump it into our database. I guess I could write a macro to do so, but I don't know how.

The Fix:

Nor do you need to. Word can strip the data out of the form for you. Open the form template (or document), choose Tools Options, click the Save tab, and check the "Save data only for forms box.

Once you've done this, Word selects the "Plain text" item in the "Save as type" drop-down list when the user displays the Save dialog box. When the user clicks the Save button, Word displays the File Conversion dialog box, allowing the user to check the encoding of the text file before saving it. The resulting text file, which is in comma-separated value (CSV) format, contains only the text entered in the form and the values of any checkboxes (1 if checked, 0 if unchecked).



Word Annoyances
Word Annoyances: How to Fix the Most ANNOYING Things about Your Favorite Word Processor
ISBN: 0596009542
EAN: 2147483647
Year: 2003
Pages: 91

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net