Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'm trying to populate the fields of a protected form via VBA code from Access via automation. Most of the time it works fine but I am running into an error on a text field. The message says the string I built and tried to move to the text field is too long. The string length is 409.
    When I manually type into the text field there doesn't seem to be a limit. I put over 1,800 characters into the field this way with no problem. I tried copying those 1,800 characters and pasting them into the field (10 times!) and still had no problem.
    Any suggestions? Why would there be a limit in VBA if there isn't any manually? My code says:
    doc.FormFields(173).Result = strRec
    Where strRec is 409 characters long, doc is the Word document object, and FormFields(173).
    Is there a better way to do this?
    Thanks

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    I can't answer your question about limits or the possible reasons for them.

    [quote name='VBA-Bumbler' post='774140' date='07-May-2009 09:56']Is there a better way to do this?[/quote]
    I think .Result = string is the only way to write to a FormField in a protected document.

    Do you really need the text to be in a FormField?

  3. #3
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Unfortunately, in this case, yes. The documents are prepared and locked by the legal department. We are just trying to automate the use of the documents.
    Thanks for your reply.

  4. #4
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post
    By all accounts this has been a longstanding problem. See http://word.mvps.org/FAQs/MacrosVBA/...mFldResult.htm for some workarounds.

  5. #5
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you William! There is comfort in knowing it's not just me. Both workarounds in the article require unlocking the form. Since the documents I'm working with are password protected by our legal department, that isn't an option for me. I wonder if I could use copy and paste somehow. I could open a new document and put the string in there, then copy it. Can I paste to a formfield?
    Thanks

  6. #6
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yee Haa!!! It worked! Here's my code:

    Set doc = appWrd.Documents.Open(the name of my protected form document)
    Set doc2 = appWrd.Documents.Add
    (work with doc filling in a bunch of formfields from Access form fields)
    (build the strRec variable from Access subform formfields - in this case it was 497 characters long)
    doc2.Activate
    doc2.Paragraphs(1).Range = strRec
    doc2.Paragraphs(1).Range.Select
    appWrd.Selection.Copy
    doc.Activate
    doc.FormFields(173).Range.Select

    I'm happy! Maybe this will help someone else too.
    Thanks

Posting Permissions

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