String too long error

K

KateP

I am a complete novice at programming in Word so please bear with me. I am a
developing a Lotus Notes application that needs to output a document to Word.
I have created a tabular Word template and am outputting the individual
fields as strings, so for example:

worddoc.FormFields(1).result = RaisedBy

This is working fine for all of the fields except for the final one which is
a text field that can contain a fair amount of data and is generating a Word
"Script too long error"..

Does anyone have any suggestions as to how I can get around this? Could it
be because the field is contained in a table cell? I've been really
struggling with this output and the best way to do it as I have no experience
of the features of Word at all.

Any help would be greatly appreciated.

Kate
 
H

Helmut Weber

Hi Kate,

the result is limited to 256 characters,
as far as I see,
and even putting that amount of characters
in a formfield doesn't make much sense to me.

Have a look at this sample:

Sub Test09978()
Dim s As String
s = "We the People of the United States, in Order to form " & _
"a more perfect Union, establish Justice, insure domestic " & _
"Tranquility, provide for the common defence, promote the " & _
"general Welfare, and secure the Blessings of Liberty to " & _
"ourselves and our Posterity, do ordain and establish this " & _
"Constitution for the United States of America."

s = Left(s, 251) & "[...]"
ActiveDocument.FormFields(1).Result = s
End Sub

You may use:

RaisedBy = Left(RaisedBy, 251) & "[...]"
worddoc.FormFields(1).result = RaisedBy


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

KateP

Hi Helmut

Many thanks for your post. You say "putting that amount of characters in a
formfield doesn't make much sense", please could you advise what would be a
better way of doing this, I've been really struggling..

Thank you in advance.

Kate
 
H

Helmut Weber

Hi Kate,

I'm afraid there is no solution.
Nothing larger than the form fits into the form.
Forms are forms, that's their very nature.
If you have to put something, which is larger
than the form, into the form,
then either you cut it down, or you resign.

How much space have you got?
Lets say 25 characters.
More then 25 characters would ruin the layout of your doc.

So cut all down to 20 characters and add [...],
which is the scientific way,
or cut all down to 22 characters and add ...
to indicate, that there something had to be chopped off.

Like RaisedBy = Left(RaisedBy, 22) & "..."

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Doug Robbins - Word MVP

' Macro created 05/09/98 by Doug Robbins to insert long string into
FormField

'

FillText = "Your long string"

LenFillText = Len(FillText)

FirstBit = Left(FillText, 255)

If LenFillText > 255 Then

SecondBit = Mid(FillText, 256, LenFillText - 255)

ActiveDocument.FormFields("Text1").Result = FirstBit

Selection.GoTo What:=wdGoToBookmark, Name:="Text1"

ActiveDocument.Unprotect

Selection.InsertAfter SecondBit

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

Else

ActiveDocument.FormFields("Text1").Result = FillText

End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

KateP said:
Hi Helmut

Many thanks for your post. You say "putting that amount of characters in
a
formfield doesn't make much sense", please could you advise what would be
a
better way of doing this, I've been really struggling..

Thank you in advance.

Kate

Helmut Weber said:
Hi Kate,

the result is limited to 256 characters,
as far as I see,
and even putting that amount of characters
in a formfield doesn't make much sense to me.

Have a look at this sample:

Sub Test09978()
Dim s As String
s = "We the People of the United States, in Order to form " & _
"a more perfect Union, establish Justice, insure domestic " & _
"Tranquility, provide for the common defence, promote the " & _
"general Welfare, and secure the Blessings of Liberty to " & _
"ourselves and our Posterity, do ordain and establish this " & _
"Constitution for the United States of America."

s = Left(s, 251) & "[...]"
ActiveDocument.FormFields(1).Result = s
End Sub

You may use:

RaisedBy = Left(RaisedBy, 251) & "[...]"
worddoc.FormFields(1).result = RaisedBy


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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