Results 1 to 12 of 12
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Formfield length restriction (WinXP/Word2003)

    I'm having great difficulty with a template that needs to include large chunks of text in formfields, often repeated in several places throughout the document.

    It seems that although a text formfield, if filled in manually, will accept (as far as I can tell) the entire text of War and Peace if you should wish to spend the time typing it in, if you try to programmatically replicate the contents of that field to other places/formfields within the document (as I need to do) you get a "string too long" error on anything over 255 characters. Can anyone think of a way round this?!

    I did find this MSKB entry - "Run-time error: 'String too long'" - which suggests a workaround, but I don't understand what it's doing and therefore can't adapt it for my uses. If anyone could explain to me exactly what it does I'd be grateful, and might not need another way!

    Many thanks
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    Apparently, it *is* possible to insert strings longer than 255 characters into a text formfield while the document is unprotected. The code does the following:
    1. <LI>Set the text of the formfield to **** (* is just a placeholder character that is unlikely to occur in the text you actually want to insert, you could use another character if you prefer).
      <LI>Unprotect the document.
      <LI>Move the insertion point to between the first and second * (or whatever character you used).
      <LI>Insert the long text.
      <LI>Remove the *s from the formfield. As a result, the formfield now contains the long text you wanted to insert.
      <LI>Re-protect the document without clearing formfields.
    Clear as mud now?

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    In other words, you can *insert* a string of whatever length into a formfield that already has something in it, but you can't just make the content of an empty formfield be any string that's longer than 255 characters? Is that correct?
    If so, how bizarre! <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    The essential point is that you must do this while the document is unprotected - you can't use Selection.TypeText while the document is protected.
    You could also insert the text into an 'empty' formfield, but the problem is that if the document is unprotected, an 'empty' formfield contains 5 spaces. It would be more work to remove those after the insertion than simply replacing a placeholder character that doesn't occur in the inserted text.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    Hi Hans, thanks for this, but the unprotected bit isn't a problem, all the programmatical work is being done while it's unprotected (are you thinking of my other post re 'tabbing' between formfields while they're protected, perhaps?!).

    However, I'm not sure that what you state is correct - that you could insert the text into an empty formfield - because that's what I've been trying to do all along! That is, replace a placeholder text string with an empty formfield and then make the result of that formfield to be the string I'm working with (in fact you helped me set up the function to do it just last week) and it works perfectly as long as the string is 255 characters or less, but then ...!

    The only thing that's different about the microsoft code that I can see is that it inserts the string into the content of an already-filled formfield, rather than making the string become the entire result of the formfield - unless I'm still understanding it wrong?!
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    In a document protected for forms, you cannot programmatically insert a string of over 255 characters into a formfield.
    In an unprotected document, you can, but you *must* insert the text inside the formfield, otherwise you'd replace the formfield with the text you insert (in other words, the formfield would disappear). That is why the code provided by Microsoft fills the formfield with a short string first.

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    That sounds good - I'll have to try it!
    Beryl M


  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    Jan, that worked like a dream! A one-line fix to a seemingly insoluble problem! Well, two, by the time I'd named the formfield so I could reference it as a bookmark. That deserves a <img src=/S/ribbon.gif border=0 alt=ribbon width=15 height=15> <img src=/S/ribbon.gif border=0 alt=ribbon width=15 height=15> star post <img src=/S/ribbon.gif border=0 alt=ribbon width=15 height=15> <img src=/S/ribbon.gif border=0 alt=ribbon width=15 height=15>, at least from my point of view!! (couldn't find a star smiley, this <img src=/S/ribbon.gif border=0 alt=ribbon width=15 height=15> was the closest!)

    Thank you!! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Beryl M


  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    Beryl,

    Thanks for the suggestion, a <IMG SRC=http://www.wopr.com/w3timages/starpost.gif> has been duly awarded.

    StuartR

  10. #10
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Overcome formfield length restriction (Word 97+)

    There's a work-around, using the "Bookmarks trick". In some ways, a FormField is also treated as a Bookmark. With this trick you can insert long strings into a FormField. As an example, try this to insert 1000 A's in a FormField:

    ActiveDocument.Bookmarks("Name").Range.Fields(1).R esult.Text = String$(1000, "A")

  11. #11
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    Beryl, you almost make me blush...
    Been away for a long weekend, hence my late reaction. I didn't come up with this myself, but found it somewhere on the net.

  12. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Formfield length restriction (WinXP/Word2003)

    Nah, it's true! And StuartR agreed with me, 'cos he made it a star post!!
    Beryl M


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •