How to set the result of a text formfield using VBA, if the string is longer then 256 characters

Article contributed by Dave Rado

If you use:

Dim FmFld As FormField, Str1 As String
Str1 = (a long string > 256 characters)

Set FmFld = ActiveDocument.FormFields(1)
FmFld.Result = Str1

You get an error: String too long (a ridiculous design feature, given that you can do it manually without problems!).

Same if you use:

ActiveDocument.Formfields("Text1").Result = Str1

You can get round this by using:

ActiveDocument.Unprotect
FmFld.Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

Or if you're referring to the formfield by name:

ActiveDocument.Unprotect
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

See also: How to set the result of a text formfield in a Word 2000 table, using VBA, if the string contains carriage returns