Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Mar 2002
    Location
    Decatur, AL
    Posts
    53
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Print Word doc fr Access (Office 2000 Premium)

    I think this should be really easy, but I'm stuck. I have a 3-page Word document with some screwy formatting (e.g. 2 pages are Portrait, 1 is Landscape, 1 of them has columns, there are Draw objects on 1, etc.). There is no merging required from my Access application, all I want is a button on a form that prints this Word doc. If it works in the background without opening Word that would be even better. Can anyone help?

    Thanks in advance.
    Kathi

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word doc fr Access (Office 2000 Premium)

    Put this code in the On Click event of your button :
    <pre>Dim wrd As New Word.Application
    wrd.Documents.Open "d:test.doc"
    wrd.PrintOut False
    wrd.Quit
    Set wrd = Nothing</pre>

    Replace d:test.doc with your own document and his path.
    You have also to set a reference to Word.
    In the VBE editor, select Tools / References and scroll down to Microsoft Word 9.0 Object Library and check it.
    Francois

  3. #3
    Star Lounger
    Join Date
    Mar 2002
    Location
    Decatur, AL
    Posts
    53
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Print Word doc fr Access (Office 2000 Premium)

    Thank you, my friend. I commented out the last line and all is working perfectly now. You are the master!!!

  4. #4
    Star Lounger
    Join Date
    Mar 2002
    Location
    Decatur, AL
    Posts
    53
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: Print Word doc fr Access (Office 2000 Premium)

    Hi everyone. Wow, over a year ago I got outstanding help with simple printing of a Word document.

    As you've probably guessed I now need to take the issue further. Here's the situation:
    The overall project is to create test procedure books for over 60 differently configured locations. Each location can have any or all of 10 different subsystems. Each subsystem can require any or all of numerous test procedures, and a single location's subsystem may require 2 or more of the same test procedure. Is that clear? (In all, there are over 60 individual test procedures)

    The status right now is that a team has produced all of the individual test procedures as individual Word documents. They all follow the same required format as such:
    1.1.1 Name of Test
    1.1.1.1 Introduction
    1.1.1.1.1 Purpose of Test
    1.1.1.1.2 Subsystem or Equipment to be Tested
    etc.

    Each Word doc begins as if it is the 1st test proc in a particular book, i.e. they all start with the number "1". The thinking was to simply append each required doc, in order, into a "master" document for each location. Then auto-renumber the master, create a table of contents, slap in a cover page, and call that location done. They got ONE done, and quickly realized that any change to a particular test procedure would soon become a monumental task since they would have to open each master and make the same change.

    I was asked to write an application in Access that would always link the actual latest revision of each test procedure. I can PRINT, in order, all the test procedures for a particular location. BUT, they all begin with "1" AND the contract requires that each book also be delivered as a master Word document.

    Is there a way to manipulate Word via Access code to append the required docs into a master file and save it as a new file? I don't even need to be able to print it from Access, just create it.

    ANY suggestions or solutions will be greatly appreciated -- it's my little brother that is responsible for this project so I'm quite motivated to help! Thanks in advance, Kathi

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word doc fr Access (Office 2000 Premium)

    The master document feature in Word is very frail - see Why Master Documents corrupt. If you want to use it, please make sure that you have backup copies of all subdocuments, in case something goes wrong (making backups is always a good idea, but with master/subdocuments it is imperative).

    I haven't really tested the following code, but I hope you can use it or adapt it to your needs.

    Sub InsertSubDocs()
    ' Path to the subdocuments - change as needed, but keep the trailing backslash
    Const strPath = "F:SubDocs"
    Dim strFile As String
    Dim wrdApp As New Word.Application
    Dim wrdDoc As Word.Document

    On Error GoTo ErrHandler

    Set wrdDoc = wrdApp.Documents.Add

    strFile = Dir(strPath & "*.doc")
    Do While Not strFile = ""
    wrdDoc.Subdocuments.AddFromFile strPath & strFile
    strFile = Dir
    Loop

    ExitHandler:
    On Error Resume Next
    wrdDoc.SaveAs strPath & "Master.doc"
    wrdDoc.Close SaveChanges:=False
    wrdApp.Quit
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    You can change the line

    Set wrdDoc = wrdApp.Documents.Add

    into

    Set wrdDoc = wrdApp.Documents.Open("F:WordMaster.doc")

    (with the appropriate path/filename) to use an existing document instead of a blank new one.

Posting Permissions

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