PDA

View Full Version : Length limit on Bookmark name in FormField



wrecks
09-12-2008, 03:35 PM
When I create a FormField (using the Forms toolbar, Text Form Field button), I find that the length of the bookmark name is limited to 20 characters. Yikes! We had a plan to use longer names is a very large document with hundreds of form fields.

Does anyone know of a way to get longer names?

(I'm using Word 2003.)

macropod
09-13-2008, 02:14 AM
Hi wreks,

Apparently that's the formfield bookmark limit and you can't change it. For other bookmarks, the limit is 40 characters.

fumei
09-15-2008, 11:02 AM
There is a sort of workaround. It is true that a formfield creates a bookmark. It is important to understand that they are different.

Say you want a formfield to be "named" MoreThanEnoughToGetToHeaven. Well, you can't, as it has 27 characters.

Typing it in the Properties you would end up with MoreThanEnoughToGetT - 20 characters.

HOWEVER, you can do this:

1. delete the name of formfield. The formfield is still be there, but it now have no Bookmark.

2. select the formfield and make a bookmark...naming it, say, MoreThanEnoughToGetToHeaven.

Now the code:
ActiveDocument.Bookmarks("MoreThanEnoughToGetToHeaven").Range.Text

will get the value of the text in the formfield.

This can also be done with checkboxes.

ActiveDocument.Bookmarks("MyReallyLongNamedCheckbox").Range _
.FormFields(1).CheckBox.Value

The formfield has NO name, but it IS bookmarked. You can get the value from that.

wrecks
09-15-2008, 03:56 PM
Thank you, fumei -- that's a very clever idea!

If our program was running the whole show via VBA, this would do the trick. But in our situation the customer maintains a very large Word document with zillions of fields, and this would require the document author to maintain two Word objects (bookmark and form field) for every field.

Our application will open this document as a template and loop through all the form fields, setting FormFields(i).Result with data retrieved from an Access database. [Importantly, the form field's default value and format specs would then come into play.] The bookmark name was to be a fairly lengthy string that would identify the table, row, and column. We wanted the string to be pretty long so that the document author could compose it, and later look at the string and understand it. If we used form fields and their bookmarks, everything would appear in the form field properties dialog.

I think we may resort to putting our lengthy "bookmark" name into the form field's "Add Help Text -> Status Bar -> Type your own" area. I'm not happy about this, but it does get everything into one Word object.


P.S. -- Who made up this 20-character limit, anyway? Reminds me of MS-DOS days where every character was a big deal! :dunno

fumei
09-16-2008, 08:43 AM
Well I don't all the details of your situation but...

1. You could still use Formfields(i).Result if you are looping through them all, as using (i) - as an Index number - has no connection with using a name.

2. I do not know what you mean exactly by "maintain two Word objects (bookmark and form field) for every field". Maintain? What do you mean by maintain?

The fact is that they ARE two separate objects. It is just that most people think of them as interchangeable.

3. Again, I do not know the exact details, but IF the formfields are given long names - via Properties - the string will be truncated at 20 characters. Fine. Now go through and delete the internally generated bookmarks (with the 20 characters). This does NOT affect the formfields themselves in any way at all.

Now go through and re-bookmark the formfields, giving the bookmarks the longer name.

EXAMPLE:

Bookmark for formfield: MoreThanEnoughToGetToHeaven
Formfield name: MoreThanEnoughToGetT

Now you can extract the actual formfield name from the bookmark name.

Left(bookmark.name, 20)

Obviously you should test first to see if it IS 20+ characters.

You could then use an array of the bookmark names to get the formfield names.

However, again, if you are looping via Index number - Formfield(i) - the name does not matter anyway.

"but it does get everything into one Word object." No, it does not. They (formfield object, bookmark object) are, and will remain, two distinct objects.

PS. Could not agree more. There is no serious reason why there should be such a limit as 20 characters. It is string property and with modern systems it seems ridiculous that Word can not handle this.

wrecks
09-16-2008, 09:23 AM
Well, yes, you are correct about "one Word object" really being two. It's a question of how the user perceives it.

I totally understand how we could implement your suggested scheme.

But we are worried about the person who builds and maintains the document. When he double-clicks a field, we would like him to see everything in one dialog. The native Word behavior is perfect except for the length limit.

If we use your technique and wrap a bookmark around each field, the author must double-click the field to edit, say, the numeric format. But then to see or change the bookmark name, he must use Insert|Bookmark.

One advantage of putting our lengthy pseudo-bookmark name into the form field's "Add Help Text -> Status Bar -> Type your own" area is that the user can put Word into "protect form" mode and then he sees our name in the status bar.

fumei
09-16-2008, 11:53 AM
All perfectly reasonable.