Results 1 to 16 of 16

Thread: Insert new line in table

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Insert new line in table

    When I insert a new line into a string that pulls into a table via a docvariable I get a box of sorts. I've tried vbCrLf and Chr(13), both of which work elsewhere but not in the table.


    The new lines are after LLP and before Oxnard

    What can I use for a line feed within a table?
    Attached Images Attached Images  

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Insert new line in table

    How are you adding the text to the table and how is the table formatted?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Insert new line in table

    Quote Originally Posted by silvrwood
    When I insert a new line into a string that pulls into a table via a docvariable I get a box of sorts. I've tried vbCrLf and Chr(13), both of which work elsewhere but not in the table.


    The new lines are after LLP and before Oxnard

    What can I use for a line feed within a table?

    Have you tried Chr(10) & Chr(13)?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Insert new line in table

    vbCrLf is the same as Chr(10) & Chr(13).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Insert new line in table

    Quote Originally Posted by RobDog888
    vbCrLf is the same as Chr(10) & Chr(13).

    I know but I have noticed that you need to enter it in this particular order (Chr(13) & Chr(10)) for it to work in Access XP and prior Reports. See attached image.


    Last edited by Mark Gambo; Jul 2nd, 2005 at 09:13 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Re: Insert new line in table

    Alas, I had no luck with Chr(13) & Chr(10). I tried them in reverse just to be sure. Putting a space after the text on the first line at least enables the next line to drop to another line, but the boxes still appear.

    In Word, in the document, I have inserted a docVariable field into a table. The table alignment is left with no text wrapping & standard margins. It is set to auto-resize to contents. The row is allowed to break across the page & there is no border. Am I leaving out anything that might be pertinent?

    In the code I have created a string then assigned that string to the value of the docVariable:

    Code:
    Dim OptExecOO As String
    
    OptExecOO = "Nordman Cormany Hair & Compton LLP " & Chr(13)  & _
        "1000 Town Center Drive, Sixth Floor " & Chr(13) & _
        "Oxnard, California  93030"
    
    'ActiveDocument.Variables.Add Name:="OptExec", Value:=" "
    
    If ExecOutOpt.Value = True Then
    
        ActiveDocument.Variables("OptExec").Value = OptExecOO
        
        Else
        
            ActiveDocument.Variables("OptExec").Value = OptExecIO
                    
    End If

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Insert new line in table

    Have you tried vbNewLine?

  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Insert new line in table

    Did you try:

    VB Code:
    1. Dim OptExecOO As String
    2.  
    3. OptExecOO = "Nordman Cormany Hair & Compton LLP " & [COLOR=Red]Chr(13) & Chr(10)[/COLOR] & _
    4.     "1000 Town Center Drive, Sixth Floor " & [COLOR=Red]Chr(13) & Chr(10)[/COLOR] & _
    5.     "Oxnard, California  93030"
    6.  
    7. 'ActiveDocument.Variables.Add Name:="OptExec", Value:=" "
    8.  
    9. If ExecOutOpt.Value = True Then
    10.  
    11.     ActiveDocument.Variables("OptExec").Value = OptExecOO
    12.    
    13.     Else
    14.    
    15.         ActiveDocument.Variables("OptExec").Value = OptExecIO
    16.                
    17. End If

    I used the following code in order to produce the attached image:

    VB Code:
    1. Dim OptExecOO  As String
    2. OptExecOO = "Nordman Cormany Hair & Compton LLP " & Chr(13) & Chr(10) & _
    3.     "1000 Town Center Drive, Sixth Floor " & Chr(13) & Chr(10) & _
    4.     "Oxnard, California  93030"
    5. Me.Text0 = OptExecOO
    Attached Images Attached Images  
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Insert new line in table

    Quote Originally Posted by Hack
    Have you tried vbNewLine?
    This solution also will work for you.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Re: Insert new line in table

    For some reason none of those solutions are working for me in a Word 2003 table. They work fine elsewhere in the document. Part of it seems to be related to the font. We use Century Schoolbook. When I change the font the box looks more like a hidden box, but it still consumes a space on the line before the start of the text as opposed to at the end of the preceeding line where it would not take up space.

    For the time being I have added spaces between the text to force it to wrap at the margin.

  11. #11
    Lively Member
    Join Date
    Apr 2005
    Posts
    103

    Re: Insert new line in table

    Where exactly is the string coming from? Are you sure it doesn't have the box character in it before you go pasting it into the table?
    Otherwise try Chr(11) to add a soft-return?

  12. #12

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Re: Insert new line in table

    I declare a string in the User Form code, then set its value directly within the code, i.e.

    Dim problemString As String
    problemString = "Nordman Cormany Hair & Compton" & Chr(13) & _
    "etc..."

    So it's not pulling from anywhere else. I haven't tried Chr(11) yet. I will do that and respond accordingly.

  13. #13
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Insert new line in table

    Quote Originally Posted by silvrwood
    I declare a string in the User Form code, then set its value directly within the code, i.e.

    Dim problemString As String
    problemString = "Nordman Cormany Hair & Compton" & Chr(13) & _
    "etc..."

    So it's not pulling from anywhere else. I haven't tried Chr(11) yet. I will do that and respond accordingly.

    Can you post a sample project?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  14. #14

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Re: Insert new line in table

    Quote Originally Posted by silvrwood
    Alas, I had no luck with Chr(13) & Chr(10). I tried them in reverse just to be sure. Putting a space after the text on the first line at least enables the next line to drop to another line, but the boxes still appear.

    In Word, in the document, I have inserted a docVariable field into a table. The table alignment is left with no text wrapping & standard margins. It is set to auto-resize to contents. The row is allowed to break across the page & there is no border. Am I leaving out anything that might be pertinent?

    In the code I have created a string then assigned that string to the value of the docVariable:

    Code:
    Dim OptExecOO As String
    
    OptExecOO = "Nordman Cormany Hair & Compton LLP " & Chr(13)  & _
        "1000 Town Center Drive, Sixth Floor " & Chr(13) & _
        "Oxnard, California  93030"
    
    'ActiveDocument.Variables.Add Name:="OptExec", Value:=" "
    
    If ExecOutOpt.Value = True Then
    
        ActiveDocument.Variables("OptExec").Value = OptExecOO
        
        Else
        
            ActiveDocument.Variables("OptExec").Value = OptExecIO
                    
    End If
    It's the same as I indicated here.

  15. #15
    New Member
    Join Date
    Feb 2006
    Posts
    1

    Thumbs up Re: Insert new line in table

    Hi,
    The problem not ur script but MS Word template, for Word 2000 & 2003 u need to Place an Enter Key(new line) under the {DOCVARIABLE "YOUR_FIELD_NAME" \* MERGEFORMAT} field if ur field is in the table. If it's not in the table it's ok u wont see the square box.

    I found a bug, If u don't add enter key under the "DOCVARIABLE" field & after u exported the data into the "DOCVARIABLE" field u will see the square box & if u place u cursor under the "DOCVARIABLE" field press Enter Key BOOM!!! ms word crash.

    Foo.

  16. #16

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    SoCal
    Posts
    54

    Resolved Re: Insert new line in table

    Thank you for this information. I will keep it if the firm decides to use this project again, or if such a need presents itself once more.

Posting Permissions

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



Click Here to Expand Forum to Full Width