Results 1 to 11 of 11
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Form Field (Word XP)

    I want to use VBA to fill a FormField, but the result requires several lines.

    I've used ActiveDocument.FormFields("Address").Result = "line one" & vbCR & "line two" & vbCR & "line three"; the results is a little square where I expect the paragraph. Instead of vbCR, I've used vbLF, Chr$(11), Chr$(13). Is this not something that VBA can do in a form field? I can manually create a new line.

    Thanks.
    Richard Barrett

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Form Field (Word XP)

    This works as expected for me so I don't know what the problem might be. Have you tried vbCrLf as well?

    I would try to create a new formfield and try your code on that one - perhaps there is something about the current formfield that makes it a single line entry.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Form Field (Word XP)

    Thanks for your reply. I did try this in the same document, with a newly created form field... no luck. I then tried it in a new document, and it worked as expected. The difference: the form field is in a table in my original document. That seems to be the deal breaker.

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

    Re: Form Field (Word XP)

    Try using a manual line break Chr(11) instead of a paragraph break vbCr.

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Form Field (Word XP)

    Still no luck. I've tried every vb Constant and Chr(x) I can think of. They all function as expect... unless the field is in a table.

    As it happens, the multi-line text in its original format has the line breaks represented by pipes (|). So I can parse that and fill several separate text fields. Not as efficient, but it will give the desired results. Better yet, I can convince the users that spilling the text out horizontally will save space on the page.

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

    Re: Form Field (Word XP)

    What does the macro in the attached document do when you try it?
    Attached Files Attached Files

  7. #7
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Form Field (Word XP)

    The line feed, para mark, etc. represented by a little square. (See attached image.)
    Attached Images Attached Images

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

    Re: Form Field (Word XP)

    There must be something wrong with your installation. Does the attached modified version work any better?
    Attached Files Attached Files

  9. #9
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Form Field (Word XP)

    Your attachment worked fine. I see what you've done differently. I used

    ActiveDocument.FormFields(1).Result = "one" & vbCR & "two" * vbCR & "three"

    Your started with ActiveDocument.Bookmarks....

    That seems to make the difference. The method that I used is what VBA Help indicates; your method actually works well. I'll go with your method. Thank you!

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

    Re: Form Field (Word XP)

    An essential part in the code in my latest attachment is that the document is unprotected, then the value is set, and finally the document is protected again. The line using Bookmarks(...) etc. won't work if you leave the document protected.
    Source: How to set the result of a text formfield in a Word 2000 table, using VBA, if the string contains carriage returns on the Word MVP site.

  11. #11
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Form Field (Word XP)

    I understand that the form must be unprotected first. That's not really a drawback in this situation.

Posting Permissions

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