How to print a word document from Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omajay
    New Member
    • Mar 2010
    • 2

    How to print a word document from Access

    I have multiple documents that need to be printed on a daily basis and I want to create a Access form with buttons to print these documents.

    I've created a form to open a word doc(s), but all I really need to do is just print the document.

    I've got to imagine it's pretty simple, but I can't find anything in my searches to help me out.

    Any ideas?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    Opening a document in Word is relatively straightforward . There may even be a way (I expect there is - but it's not Access technical) to open it and print it immediately. If not however, you'll need to open it under the control of the Access code. This is a different issue altogether and requires Application Automation.

    Comment

    • omajay
      New Member
      • Mar 2010
      • 2

      #3
      I've been able to find the code to print a Word doc from Access:
      Code:
      Private Sub Command1_Click()
      Set objWord = CreateObject("Word.Application")
      objWord.Visible = True
      Set objDoc = objWord.Documents.Add()
      
      objWord.PrintOut , , , , , , , , , , , , "D:\Documents and Settings\jpapke\Desktop\macrotester.doc"
      
      objWord.Quit
      
      End Sub
      Two other issues I must tackle are;

      1) telling what tray to pull the paper from (I need it to pull tray #2 because it's yellow paper). I believe this is handled right after the PrintOut method above and should take the place of one of the "commas"

      2) the other issue is that it's printing the "Document Settings" page after each time that I print. Any ideas on how to tell it to stop that?

      Thank you,
      Jay
      Last edited by NeoPa; Mar 15 '10, 09:18 PM. Reason: Please use the [CODE] tags provided

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        You can set the printer by using:
        Code:
        objWord.ActivePrinter = "CutePDF Writer"
        I find that If I want to do stuff in Word or excel, the easiest is to start a macro recording, do the stuff I want, then stop the recorder and view the code. It might need small adaptations to work from within Access, but your 90% of the way there after looking at the macro.

        That said, I don't know how to switch around the tray (Paper Source) :)

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32653

          #5
          Originally posted by omajay
          1) telling what tray to pull the paper from (I need it to pull tray #2 because it's yellow paper). I believe this is handled right after the PrintOut method above and should take the place of one of the "commas"
          I don't believe so Jay. This is so easy to check though. Simply use the help system for the Application.Pri ntOut method. That lists all the parameters available, and what they are for. I did it already though, and I didn't find anything there to control which tray to use. You should really consider checking things out in Help before posting a question.

          Comment

          Working...