Count remaining characters in a form field

G

GaryatBeowulfs

I posted this over in the general area but it's more of a programming issue I
think so I wanted to post it here as well.

Hi all,

I was wondering if it's possible to display the number of characters
remaining in a form field. I have a text field that is limited to 650
characters that a user can enter questions/ comments in. In another field I'd
like to keep a count of remaining characters because I wouldn't want the user
to manually keep track of 650 characters.

Is there a way to do this?

btw I'm using Word 2003 and while I have some programming experience, a
decent understanding of writing formulas in Excel and Access. I've never
tried doing this in Word before.

Thanks in advance for any help
 
J

Jay Freedman

GaryatBeowulfs said:
I posted this over in the general area but it's more of a programming
issue I think so I wanted to post it here as well.

Hi all,

I was wondering if it's possible to display the number of characters
remaining in a form field. I have a text field that is limited to 650
characters that a user can enter questions/ comments in. In another
field I'd like to keep a count of remaining characters because I
wouldn't want the user to manually keep track of 650 characters.

Is there a way to do this?

btw I'm using Word 2003 and while I have some programming experience,
a decent understanding of writing formulas in Excel and Access. I've
never tried doing this in Word before.

Thanks in advance for any help

Hi Gary,

I played with this a bit, and it appears not to be possible with a text
field in a protected form. (Now that I've said that, somebody will probably
come along to show how it can be done. <g>) The problem is that there isn't
any document event that fires on a keydown or keypress inside the form
field, so a macro won't run until the user exits from the form field, which
is too late.

It certainly can be done in a text box in a UserForm (just write a
TextBoxX_Change procedure in which you calculate the number of remaining
characters and put that into the caption of a label). Make a macro that
shows the UserForm and then writes the resulting text into the form field in
the document; and make the macro fire on entry into the form field.

See http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm to get
started.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
F

fumei via OfficeKB.com

Display where?

The set length is the .Width property of a text formfield. The following
displays a message of the remainder count of a text formfield ("Text1").
Text1 is set for 300 characters. The text in the formfield is:

This is some text and the remainder should be 251

or 49 characters

Dim oFF As FormField
Set oFF = ActiveDocument.FormFields("Text1")
MsgBox oFF.TextInput.Width _
- Len(oFF.Result)

would display 251

If you put "four" into the formfield, it would display 296

Hope this helps.
 
G

GaryatBeowulfs

fumei via OfficeKB.com said:
Display where?

The set length is the .Width property of a text formfield. The following
displays a message of the remainder count of a text formfield ("Text1").
Text1 is set for 300 characters. The text in the formfield is:

This is some text and the remainder should be 251

or 49 characters

Dim oFF As FormField
Set oFF = ActiveDocument.FormFields("Text1")
MsgBox oFF.TextInput.Width _
- Len(oFF.Result)

would display 251

If you put "four" into the formfield, it would display 296

Hope this helps.
First, thanks to for the suggestions
In answer to your question on where I'd like to display the number, I'd like
it to show up above the text area where the user enters their
comments/questions.

Currently, I have a section on the form with the heading -
Questions/Comments and under that is a single table cell with a form field in
it. The user enters their comments here. I was hoping to be able to have a
counter next to Questions/Comments that would display the number of
characters remaining as they typed.

I haven't tried using the script editor in Word before and I can't quite
figure out how/where to insert the code. Could you point me in the right
direction?
 
G

GaryatBeowulfs

Thank you, I will experiment with this idea as well. I am quite a beginner
when it comes to writing behind the scenes code and macros in Word documents
and making the documents interactive but I am quite interested in the
possibilities so I look forward to learning more.
 

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