PDA

View Full Version : Solved: FormField.Result Length Limit



Demosthine
09-28-2008, 11:45 AM
Hey Everyone.

For work, I have a report that I do regularly on my Blackberry Phone. I have a simple spreadsheet that has three columns. Column B is associated with the FormField Name in a Word Document and Column C is the value I want to put into the FormField.

I have come across a limitation when I attempt to assign the Excel values to the Word FormField. It causes an error if I am assigning more than 256 characters.

I have found a Thread [Thread=22190]here[/ThreadID] that relates to the FormField's Name being too long and it is recommended to use Bookmarks. When I try this by assigning the Excel value to Bookmarks(FieldName).Range.Text, it errors out again. I would assume this is because the document is protected.

Is there a way around this while keeping the document protected?

Thanks.
Scott

macropod
09-28-2008, 02:00 PM
Hi Demosthine,

Since you need to unprotect the document, try:
Sub UpdateFormField(FFName As String, FFText As String)
Dim Pwd As String
Pwd = "YourPassword"
With ActiveDocument
.Unprotect Password:=Pwd
.Bookmarks(FFName).Range.Fields(1).Result.Text = FFText
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=Pwd
End With
End SubWhere your calling routine passes both the formfield's name (FFName) and content (FFText) as parameters.

If you've got other routines that need to operate on the document in an unprotected state, you can move:
Dim Pwd As String
Pwd = "YourPassword"outside the sub to make them available to all the subs in the module.

Demosthine
09-28-2008, 02:42 PM
Hey MacroPod.

Due to the nature and size of the report, unprotecting it isn't going to be the best option, so I've avoided that possibility. It's a complex report with a large amounts of tables that users mess up.

But at the same time, you provided me with the answer I needed regardless of protection. The code below worked beautifully.


docReport.Bookmarks(strField).Range.Fields(1).Result.Text = .Cells(intRow, 3).Value


Thanks for the help.