Results 1 to 3 of 3
  1. #1
    Perineum is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    28

    Creating Word doc with access, paragraph break creates leading space

    From a MS Access form I use VBA code to create a Word doc with text form fields. When there is a paragraph break (enter is pressed) in the text field in Access, in the Word doc a leading space appears on the next line. I don't want the leading space. I can't seem to find a solution for this. I've tried Trim, LTrim, Replace, plain text, rich text, etc. The functions will remove a leading space at the beginning of the paragraph but not within the paragraph. When I look at hidden codes, I see the backwards P symbol. When I do a search in word it does not find the paragraph breaks inside the text form field.



    Any help would be greatly appreciated.

    thanks

  2. #2
    DougsGraphics is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2016
    Location
    New Mexico
    Posts
    11
    If I understand correctly, you are using an Access form to collect text which you then insert into a text form field in a Word document and if a "return" is inline in the text collected, you get a newline and an indent at that point in the Word document?
    If you don't want to allow returns, you can either set the default behavior on your form field in Access as "Enter Key Behavior" property set to "Default", or use VBA find and strip out every vbCrLf. If you want to allow paragraphs, but just don't want the leading space, I suspect your formatting of the text field in Word will need to be changed -- right click the field in your template, select "Paragraph..." and be sure the indentation and spacing are set the way you want them to behave.

  3. #3
    Perineum is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    28
    Thanks for the reply. There was nothing in the MS Word parameters to get rid of the leading space. I do want paragraph breaks but I don't want the leading space. Your idea of stripping out the vbCrLf lead me to find a function that did that. I modified it to keep the carriage return but remove the LF (Line Feed) which created a leading space on the next line. Many thanks!
    Public Function CleanString(strSource As String) As String
    On Error GoTo CleanStringErr

    'convert all vbCrLf to vbcr to get rid of the LF character which creates a space
    strSource = Replace(strSource, vbCrLf, vbCr)

    'Remove any leading or training spaces and return result
    CleanString = Trim(strSource)
    Exit Function
    CleanStringErr:
    'Insert error-handling code here
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 09-18-2015, 09:02 PM
  2. help creating a form to transfer data from word to access
    By cc.caroline15 in forum Programming
    Replies: 9
    Last Post: 02-22-2015, 06:55 PM
  3. Creating Word 2010 Charts using Access Database
    By tbelly82@gmail.com in forum Access
    Replies: 2
    Last Post: 05-28-2014, 06:16 AM
  4. Leading Spaces and space after name
    By Sumanth.Ganjam in forum Access
    Replies: 5
    Last Post: 11-13-2013, 04:04 AM
  5. Replies: 5
    Last Post: 10-28-2010, 09:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums