Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting to Word: Odd Line Breaks, etc. 1

Status
Not open for further replies.

NMiller007

Programmer
Nov 15, 2006
65
US
I have inherited a report project that requires an export to Word for editing. The export code is in place, but it is acting funny. There are paragraph marks which seem to be placed incorrectly. I have edited the size of my report to a width which is much smaller than the Word document, but I still am getting some paragraph breaks in the middle of paragraphs..

The report is just a text letter. There are no graphics or anything like that, so I figured an import to Word would work fine.

I think the problem is that on the longer paragraphs, I have a paragraph break (can see them when I show formatting marks) at the end of every line. Is there a way to not export these paragraph breaks and let Word do the wrapping?

Thanks,

Neil
 
Since you mentioned that "the export code is in place," I assume that it is the VB code using Word object model to export data.

The paragraph breaks may come from two places. First, it may be added by the VB code. So look for constants being used as line breaks or methods of adding line breaks in Word, such as "InsertParagraphAfter". Second, these line breaks may exist in the data you exported. For example, you may export a text fields where the user typed in line breaks.

Hope this helps.

Seaport
 
Thanks for the quick reply.

The export is being done using an OutputTo action in an Access Macro. The format is RTF. What do you mean by the "Word object model"?

Also, I looked back at the text box, and there isn't an "insert paragraph after" property; am I missing something?

Also, there are no breaks in the text. It is a formula which combines static text with some information from the query. One time, I noticed the paragraph break came in the middle of someone's name (which is pulled from the query), even though their first name was the first word on the line.

Would I be better off using labels and setting the captions in a VB macro? Could this have anything to do with the fact I'm using text boxes?

What about a Word template? Most of the sections are static (although some need to be omitted for certain instances of the letter). Could I place certain sections as text into a previously created Word doc?

Thanks
 
First of all, my assumption is wrong. You are not using Word object model so ignore my first reply.

When you using "OutputTo action" to export data into a RTF you basically lose the control of the export format. I rarely use this approach so all my suggestion is to keep your formatting (in the Access report) as least as possible. Also, I donot think you can do anything about the line breaks.

On the other hand, you may try using Word object model to export data. This way you will have all control over the output format, except those line breaks that were entered by users in text fields. You need to get a book like "MS Office2000 Visual Basic Programmer's Guide." You can also get helps from the "Microsoft Office" forum.

Seaport
 
Yeah, exporting to RTF doesn't seem to work.

I happened upon some information about using automation and the Word object model (just realized that's what you were talking about). Microsoft has a guide that seems to contain all of the information I need. Unfortunately, it's seems much more complicated. I managed to create a document with two lines and saved it. Now I just need to learn how to incorporate information from my query into this code.

I'm using:
Code:
With WordRng
    .InsertAfter "Running Word From Access"
    .InsertParagraphAfter
    .InsertParagraphAfter
    .InsertAfter "Is this a second line? "
  End With

How can I append a field from a query onto these Insert statements?

Can I just open the document? Now, I'm using:
Code:
WordObj.ActiveDocument.SaveAs "G:\example.doc"

I'm going to start poring over this information and hopefully I can make some progress.

Thanks for steering me in the right direction.
 
Here are some sample code to create a new document.
Code:
    On Error GoTo eh
    
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    Dim rst as ADodb.recordset 'load data from the Access db

    Set wdApp = New Word.Application
    Set wdDoc = wdApp.Documents.Add(“xxx”) 'template


ex:
    On Error Resume Next
    
    wdApp.Visible = True
    Set wdApp = Nothing
    Set wdDoc = Nothing
    Set wdTbl = Nothing
    
    Exit Function
    
eh:

    msgbox err.number
    resume ex

Usually what I do is to create the template with some text to replace. For example, put "<<LastName>>" in the place where Last Name field is inserted. Then using VB code, you can replace the "<<LastName>>" text with LastName field from the recordset.

Seaport

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top