Alt Enter problem in creating Word doc from Access VBA

JonGG

New member
Local time
Today, 17:55
Joined
Feb 6, 2013
Messages
3
I have data in a field in a table that has CHR13 and 10 hidden characters so that the multiple lines of text will be formatted correctly.
this field is part of a query that is inserted in a Word document that I am creating from within the Access app using VBA.
When the field from the query appears on the Word doc it is recognizing the CHR13 and 10 characters and doing a CRLF, carriage return line feed
so the integrity of the text from that field is being lost and wrapping around text in the doc that I don't want.
How would I (in VBA) keep the formatted field intact when appearing in the Word doc.

Thanks. jonGG
 
When the field from the query appears on the Word doc it is recognizing the CHR13 and 10 characters and doing a CRLF, carriage return line feed
so the integrity of the text from that field is being lost and wrapping around text in the doc that I don't want.
How would I (in VBA) keep the formatted field intact when appearing in the Word doc.

It sounds like you do not want extra CrLf's for occurrences of CHR13 / CHR10, but then you make it sound like formatting is getting lost. I can not understand what you are expecting to have happen.

Do you need to search / replace the text before sending it over to Word in order to swap troublesome characters for alternate characters? Perhaps you need something along the lines of:

Code:
  'Remove any "-" characters from the partnumber which is in the strPN variable
  If InStr(1, strPN, "-", vbTextCompare) <> 0 Then
    strPN = Replace(strPN, "-", vbNullString)
  End If
 
Thanks for your response
The CHR13 and 10 characters are in the table field of a table because the text within it should be displayed on multiple lines but when this field is used in a query and output to a Word doc that I am building in VBA, Word sees these characters and interprets text following the chars as a line feed and in this case moves text from that field in the output query into the next filed in the query.
How can I keep the integrity of the field intact when output in a query in a Word doc.
 
The CHR13 and 10 characters

So per my ASCII table, are you trying to type into Word ^M / ^J characters?

Perhaps copy / paste some sample code as to where the data is coming from / where it is sent to Word.
 
The original source of the data is Excel where Alt Enter is used for line feeds to format data ondifferent lines within a cell
When the Excel file was imported into an Access table the Alt Enter (CHR10) was converted to "CHR13 & CHR10" (CRLF) to maintain the proper
multiple line formatting. When Word sees the (CRLF) in the query it breaks up the data in the query field at the CRLF and into the next query field. If I can change the CHR13 & CHR10 in the Access field that will still maintain the multiple line format and will not be recognized by Word as a line feed then my life will be alot easier. thanks for your continued interest in this problem. jonGG
 
So how about scanning the data as you send it to Word looking for the offending characters, and if found swap for vbCrLf or what ever way Word desires to receive a new line request via Automation? You could use my suggestion in #2 to accomplish that much.
 
I coded up a quick sample of my suggestion...

Code:
  'Document Header
  strBMName = "HdrProjectName"
  Set objBMRange = objWordDoc.Bookmarks(strBMName).Range
  objBMRange.Text = Me.HdrProjectName
  objWordDoc.Bookmarks.Add Name:=strBMName, Range:=objBMRange
  Set objBMRange = Nothing

  strBMName = "HdrDate"
  Set objBMRange = objWordDoc.Bookmarks(strBMName).Range
  objBMRange.Text = Me.HdrDate[B] & vbCrLf & vbCrLf & "Hi!"[/B]
  objWordDoc.Bookmarks.Add Name:=strBMName, Range:=objBMRange
  Set objBMRange = Nothing
attachment.php


Sample code of how I drive Word from Access...

Example Access VBA preparing a Word document using Range Bookmarks
http://www.access-programmers.co.uk/forums/showthread.php?t=236469
 

Attachments

  • WordCrLfSample.jpg
    WordCrLfSample.jpg
    6.2 KB · Views: 377

Users who are viewing this thread

Back
Top Bottom