 |
 |
 |
 |
 |
Please Fill Out This Form, Part 2 |
|
 |
|
 |
|
In the November/December 2000 issue of Computor
Companion, I showed you just how easy, efficient and fun it can be to build forms
using Microsoft Word. (You can find the earlier
article at www.computorcompanion.com.) In this
article, I take your new-found talents a step further
by adding a little automation to direct users to
specific locations in a form. This article involves
macros, so if you're using Word 2000, click Tools|Macro|Security and set your level to
Medium. If you don't, your macros will not run because of the default "high" security setting,
which helps avoid viruses.
 |
1 Start with your form
template
As I described in the earlier article,
you start by creating a form template. You
use tables and Form Fields to create a basic form
that requests personal information and include
Yes/No checkboxes asking whether the user is
married and/or has children. The form also had an area
to add details. However, this time, rather than
forcing the user to tab through every field, you add
a little Visual Basic for Applications (VBA) code
to help move the user to appropriate fields.
|
|
2 Rename your fields
Go through each form field, double-click it, and give it a Bookmark name other than the
default Text1, Text2, Text3. Use more descriptive names, such as bkUserName (bk for bookmark)
to help you more easily identify each location. |
|
3 Create a directional macro
The macro you will create is programming code that evaluates the user's answers. Within
the form field options, you can insert macros that
automatically run when a user jumps in or out of a form field. Your macro can then decipher
what answer the user gave and then depending on
the answer, move the cursor to the next
appropriate place on the form. To create the macro,
click Tools|Macro|Macro. Macro names must be written as one word, but you can make them more
descriptive using capitalization. So enter the
name FormSingle.
|
|
4 Set options
Your new macro determines if the user has checked single. Also be sure to click the
drop down box for Macros in: and select your form template to ensure the macro stays with the
form. Then click Create. If you've never written
programming code, you may find you slipped into a bizarre looking world: the Visual Basic Editor!
|
|
5 Write your code in the VBE
Make sure the cursor is between the Sub FormSingle() and End Sub lines (after the
comments in green). Now type the code (starting
with Set vSingle) exactly as it's written below:
This code says: Set a variable (container)
called vSingle equal to (to hold) the results of the
Checkbox called "bkSingle" (my bookmark). If the
variable called vSingle holds a result equal to "True" (i.e.,
the CheckBox is selected), you jump the user down
to the next question, which is a bookmark called "bkChildrenYes." Now close the Visual Basic
Editor program and return to your Word Form.
|
|
6 Add the macro into the field
To get this code to automatically run and move the user along the form, you need to add
this macro into the field. Open the Form Field and
add the macro to the Exit option. Form Fields have
both an Entry and Exit activation field for macros. If
you wanted code to run as soon as the user jumped into
a field, you'd add it to the Entry option. But
because you want to determine if the box was checked by
the user as they jump out of the field, you add it to
the Exit option. Double-click the Single checkbox
to open its option dialog box. Locate the Run
Macros on Exit box. Click the drop-down arrow,
select FormSingle, and click OK.
|
|
Once your macro is added into the Form Field, you now need to Protect (lock) the form to
activate the automation. Click Tools|ProtectDocument.
A dialog box appears. Don't bother with a password until you've finished all your testing. For now
just choose Forms and click OK. The form will be
locked to activate the fields. Start at the top and tab
your way through the fields. When you tab to leave
the Single checkbox, your macro will activate and
read the value of the checkbox. If you checked that
option, the macro jumps over the Spouse fields,
down to the next relevant question, which asks whether
you have any children. If you do not select Single,
the form proceeds as usual through the remaining
married, divorced, and widow fields. Be sure to test
both options. That's it! Now you can use this same
code to create more macros. Just modify the code to
read/jump to other bookmarked fields. For example,
you can have one that jumps over the children's
name/age table if users indicate they don't have kids.
For more information on forms, be sure to check out all of Dian's articles
at this link http://www.mousetrax.com/techpage.html#autoforms.
|
 |
Like the articles in Computor Companion? Check out our computer tips books!
 |
Logical Tips for Mastering Your Computer:
Quick Shortcuts, Tips, Tricks, and Techniques to Help You Use Your Computer More Effectively
Go from Computing Newbie to Power User!
|
Read about this book on Amazon |
 |
Logical Tips for Mastering the Internet:
Quick Shortcuts, Tips, Tricks, and Techniques to Help You Use the Internet More Effectively
Go from Internet Newbie to Expert!
|
Read about this book on Amazon |
 |
Logical Tips for Mastering Microsoft Office:
Quick Shortcuts, Tips, Tricks, and Techniques to Help You Use Microsoft Office More Effectively
Don't Let Microsoft Office Drive You Crazy!
|
Read about this book on Amazon |
 |
Logical Tips for Mastering Microsoft Windows:
Quick Shortcuts, Tips, Tricks, and Techniques to Help You Use Microsoft Windows More Effectively
Combat Windows Weirdness!
|
Read about this book on Amazon |
|
 |
|
|
 |
 |
Did you like this article? Let us know! Please click here to send feedback on this article. NOTE: If you have computer-related questions, you must post them on our forum. We do not answer computer questions via email. |
 |
|
 |
 |
|
 |