v2007: Text control (plain text): How to restrict length of data?

B

bixcel

I am using Word 2007.

I have set up a user input form which includes drop-down list controls and
plain text content controls.

(1) How do I restrict the number of characters that may be entered in a
plain text content control?
(I am aware that the legacy text form field allow you to set the maximum
length, but I do NOT want to use the old (legacy) method.)

(2) How do you stop carriage returns being entered in legacy text form fields?
(I am aware that the plain text content control gives an option to turn this
on/off.)

Thanks in advance
 
C

Cindy M.

Hi =?Utf-8?B?Yml4Y2Vs?=,
I am using Word 2007.

I have set up a user input form which includes drop-down list controls and
plain text content controls.

(1) How do I restrict the number of characters that may be entered in a
plain text content control?
(I am aware that the legacy text form field allow you to set the maximum
length, but I do NOT want to use the old (legacy) method.)
When the Word team was designing content controls there was a basic decision
made to *not* try to leverage Word as a "forms tool". InfoPath was designed for
this, so strict data gathering over a form is considered to be InfoPath's job.
Content Controls in Word are meant to help steer document creation. Thus, we
don't have any checkbox content controls, and no forms-type limitation
capabilities (such as limiting the type of characters, or how many characters
can be entered).

Best you could do would be a macro that triggers when the user exits the field.
It would check how many characters the field contains and take an action if
there were too many. (Delete them, return the to field, display a message...)
(2) How do you stop carriage returns being entered in legacy text form fields?
(I am aware that the plain text content control gives an option to turn this
on/off.)
There's a KB article with a macro that can prevent the user typing Enter within
a form field. See

http://support.microsoft.com?kbid=211219


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
P

p0

Hi =?Utf-8?B?Yml4Y2Vs?=,




When the Word team was designing content controls there was a basic decision
made to *not* try to leverage Word as a "forms tool". InfoPath was designed for
this, so strict data gathering over a form is considered to be InfoPath's job.
Content Controls in Word are meant to help steer document creation. Thus, we
don't have any checkbox content controls, and no forms-type limitation
capabilities (such as limiting the type of characters, or how many characters
can be entered).

Best you could do would be a macro that triggers when the user exits the field.
It would check how many characters the field contains and take an action if
there were too many. (Delete them, return the to field, display a message...)

There is an option which does exactly what you want, though it is a
highly complex one.

It is possible to map your content control to a piece of custom xml
within your document. And it is possible to define an xml schema for
that custom xml. In the schema you can define your xml elements as a
string type with limitations in length (and allowed characters). If
you assign that schema to your Word document, you can use it for
validation. Then if someone would enter more than your given number of
characters, a curly red line would appear under their input and they
wouldn't be able to save the document. Right clicking the underlined
part would even tell them what they did wrong. The problem is that by
default, the mapping of content controls and custom xml is not
entirely straightforward. You would probably need tools like
http://www.codeplex.com/Wiki/View.aspx?ProjectName=dbe

On a side note, although rather complex, custom xml is actually the
way to go as it would allow you to easily extract and manipulate the
entered data afterwards.

Yves
 

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