• Print Word doc fr Access (Office 2000 Premium)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Print Word doc fr Access (Office 2000 Premium)

    Author
    Topic
    #411907

    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

    Viewing 1 reply thread
    Author
    Replies
    • #896555

      Put this code in the On Click event of your button :

      Dim wrd As New Word.Application
      wrd.Documents.Open "d:test.doc"
      wrd.PrintOut False
      wrd.Quit
      Set wrd = Nothing

      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.

      • #896594

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

        • #970620

          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

          • #970672

            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.

      • #896595

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

    • #896556

      Put this code in the On Click event of your button :

      Dim wrd As New Word.Application
      wrd.Documents.Open "d:test.doc"
      wrd.PrintOut False
      wrd.Quit
      Set wrd = Nothing

      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.

    Viewing 1 reply thread
    Reply To: Print Word doc fr Access (Office 2000 Premium)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: