Form Fields

J

Johann Swart

I am new to Word Forms, so please bear with me.
1) One particular field has to have three digits, e.g. 005, 010, 980,
etc. Often users omit the leading zeros. Is there anything I can do to
enforce three digits? For example, when the user enter '1', on leaving
the field, it should read '001'. Altenatively, can one invoke a
message telling the user to enter three digits?
2) How can I inhibit the Enter key, e.g. inside a field of limited
characters as the one mentioned above. I have specified three digits,
but I can nevertheless hit the Enter key ad infinitum, which obviously
completely distorts the form. Alternatively, can one make the Enter
key behave like the tab key in this particular field?
3) In another field I have a two-part question; the answer is either a
date in the future, or a predefined condition in the future. I would
like the user to select either date or condition, and then have the
field where the information is entered , change accordingly; either a
defined date format, or a condition selected from a drop-down list. Is
this possible, and how?
 
P

Peter Hewett

Hi Johann Swart

First of all if you have not done so read the articles on working with protected
forms. It's background you'll need and it may reduce the number of questions
you need to ask:

How to create a template that makes it easy for users to “fill in the blanks,
without doing any programming
http://word.mvps.org/faqs/customization/FillinTheBlanks.htm

Tables, fields & forms FAQ (you want the Fields part):
http://word.mvps.org/FAQs/TblsFldsFms/index.htm


Now on to your questions:

1. Right click on the FormField and select Properties. Set the "Type" to
"Number. Set "Maximum length" to "3". Set "Number format" to "0#00".

2. You can't intercept the "Enter" key directly, you can attach the following
macro as the OnExit macro for a FormField you don't want "Enter" keys in:

Public Sub AStripCrLf()
With ActiveDocument.FormFields("Text1")
.Result = Replace(.Result, vbCrLf, vbNullString)
End With
End Sub

3. You can use either a DropDown FormField or a CheckBox FormField for this,
it's really up to you. You need to assign an OnExit macro that then "Enables"
one FormField and "Disables" the other. You set the FormFields "Enabled"
property in you macro. Say you want to enable "Text1" and disable "Text2, here's
how you'd do it:

Public Sub EnableDisable()
With ActiveDocument
.FormFields("Text1").Enabled = True
.FormFields("Text1").Enabled = False
End With
End Sub

This should give you a good start.

HTH + Cheers - Peter


(e-mail address removed) (Johann Swart), said:
 
G

Graham Mayor

Johann said:
I am new to Word Forms, so please bear with me.
1) One particular field has to have three digits, e.g. 005, 010, 980,
etc. Often users omit the leading zeros. Is there anything I can do to
enforce three digits? For example, when the user enter '1', on leaving
the field, it should read '001'. Alternatively, can one invoke a
message telling the user to enter three digits?

You can do either - but setting the field properties type to number and the
number format to 000 will insert the leading zero(s) when omitted. You can
put a help message in the properties that will print in the Word status bar
at the bottom of the screen, and you can draw users attention to this by
popping up a message from an autonew macro in the document template
eg

MsgBox "Refer to the status bar at the bottom of the screen for
instructions"

2) How can I inhibit the Enter key, e.g. inside a field of limited
characters as the one mentioned above. I have specified three digits,
but I can nevertheless hit the Enter key ad infinitum, which obviously
completely distorts the form. Alternatively, can one make the Enter
key behave like the tab key in this particular field?

You can't :( You can put the field in an unbordered table cell of fixed
dimensions which will thus not grow if the enter key is pressed and the user
will see something is amiss.
3) In another field I have a two-part question; the answer is either a
date in the future, or a predefined condition in the future. I would
like the user to select either date or condition, and then have the
field where the information is entered , change accordingly; either a
defined date format, or a condition selected from a drop-down list. Is
this possible, and how?

Use a drop down form field - or is there something you are not telling us?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP

Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
J

Johann Swart

Graham, Peter,
Thanks guys. As I said, I'm new to this, and if one
doesn't know what questions to ask, you'll not get the
right answers.
Allow me to digest this first, and I'll post an update
here, hopefully in the not too distant future.
Thanks again.
Regards
Johann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top