Replace Field with multi-line text

Posted by: david.sheppard on 18 June 2019, 5:04 am EST

  • Posted 18 June 2019, 5:04 am EST

    I want to replace a field with an address block. For example:

    Name
    Company
    Address

    When I use the paragraphs insert command, it inserts an extra paragraph between each line so that the result is:

    Name

    Company

    Address


    How can I insert the multi-line text without the extra line feeds? This is a sample of the code that I am using.

    ComplexField1 = DocSecRange1.ComplexFields.First
    ComplexField1.GetRange().Paragraphs.Insert("Name", InsertLocation.Before)
    ComplexField1.GetRange().Paragraphs.Insert("Company", InsertLocation.Before)
    ComplexField1.GetRange().Paragraphs.Insert("Address", InsertLocation.Before)

  • Replied 18 June 2019, 9:48 pm EST

    Hello,

    You can use Texts property to add multi-line text (without extra lines) and use vbcrlf for a newline, as follows:
    ComplexField1 = Section.GetRange().ComplexFields.First
    ComplexField1.GetRange().Texts.Add(vbCrLf & "Name" & vbCrLf)
    ComplexField1.GetRange().Texts.Add("Company" & vbCrLf)
    ComplexField1.GetRange().Texts.Add("Address")


    Regards,
    Esha
    ComplexField_Text.zip
  • Replied 18 June 2019, 11:23 pm EST

    Thank you for your quick response. I copied the code directly into my program. When the document opened in Word the the three text strings (Name,Company,Address) were on the same line separated by small squares. In other words, the vbCrLf characters were shown as small squares instead of being interpreted as new line characters. See attached snip.

    Once we get the multi line to work, I will need to remove the field.

  • Replied 19 June 2019, 10:39 pm EST

    Hello,

    Do you observe the same behavior with the application I attached previously?
    Please try using vbLf instead of vbCrLf. This should avoid the block within the line of text.

    Thanks.
  • Replied 20 June 2019, 4:44 am EST

    Your sample application worked as advertised. Unfortunately, I cannot get it to work on an existing document. I have attached a simple word document with 2 complex fields. The multi-line does not work on this document. The three texts are separated by squares and the field code is still in the document.

    To make it work just add doc1.load(".....\complexfield.docx")
  • Replied 20 June 2019, 5:53 am EST

    complexfield.docx
  • Marked as Answer

    Replied 23 June 2019, 10:35 pm EST

    Hello,

    I could not find your file attached. Please send it in a zip folder.
    Further, I used the attached "Test.docx" file in the same manner and observed that the text still appeared in a multiline layout, however the field code was not replaced.
    Share your file so that I can test the same at my end and escalate the issue, if need be.

    Regards.
    Test.zip
  • Replied 9 July 2019, 5:41 am EST

    Sorry for the delay in responding. Attached is a zipped word document that the multi-line code that you suggested does not work.ComplexField.zip
  • Replied 9 July 2019, 10:56 pm EST

    Hello,

    Thank you for your word file. I could observe the issue with the same and am discussing the same with the concerned team (Internal tracking ID: DOC-1342).
    Will get back to you once it is done.

    Regards,
    Esha
  • Replied 18 July 2019, 12:16 am EST

    Hi Esha, Is there any update to this issue? Replacing a field with multiple lines of text is an essential functionality for my projects. I cannot use this document api product without this functionality.

    Thank you,

    David
  • Replied 18 July 2019, 5:04 pm EST

    Hello David,

    I am getting in touch with the team regarding the update. Will get back to you once I receive any information.

    Thanks.
  • Replied 20 July 2019, 4:42 am EST

    Hello David,

    Please use GetRange().Texts.AddBreak() for adding newline break:

    ComplexField1 = Section.GetRange().ComplexFields.First
    ComplexField1.GetRange().Texts.AddBreak()
    ComplexField1.GetRange().Texts.Add("Name")
    ComplexField1.GetRange().Texts.AddBreak()
    ComplexField1.GetRange().Texts.Add("Company")
    ComplexField1.GetRange().Texts.AddBreak()
    ComplexField1.GetRange().Texts.Add("Address")


    Thanks.
  • Replied 16 August 2019, 1:11 am EST

    Thank you for your previous responses. The Add and AddBreak command worked for ComplexFields.

    Unfortunately, Add and AddBreak are not working for SimpleFields. For example, the commands:

    SimpleField1.GetRange().Texts.AddBreak()
    SimpleField1.GetRange().Texts.Add("Name")

    both return the following errors:

    'Cannot insert content of type 'Break' into parent content of type 'SimpleField' because the content to insert can be a child only for the folowing content types: Run.'

    'Cannot insert content of type 'Text' into parent content of type 'SimpleField' because the content to insert can be a child only for the folowing content types: Run.'

  • Replied 16 August 2019, 11:18 pm EST

    I found the syntax for Simple Fields. It is different than for ComplexFields:

    SimpleField1.GetRange().Runs.First.GetRange.Texts.AddBreak()
    SimpleField1.GetRange().Runs.First.GetRange().Texts.Add("Name")
  • Replied 18 August 2019, 11:10 pm EST

    Hello David,

    We're glad that you found the solution for SimpleFields.
    Also, thank you for sharing the solution here at public forums, as this can help others having similar requirement.

    Best wishes,
    Ruchir
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels