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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Word Docs 2

Status
Not open for further replies.

rossmcl

Programmer
Apr 18, 2000
128
Hi.
anyone have any clue how to print a word document from Access. I have the string of where the doc is in my function. How do I call Word to print this document WITHOUT OPENING WORD IDEALLY - is this possible?

Thanks a lot.

Ross
 
I have a form that has a filename combo box and a button to open the file. In the button's ON_CLICK event, I have the following code:
Code:
Private Sub btnRun_Click()
On Error GoTo Err_btnRun_Click

    Dim stAppName As String

    stAppName = "C:\OfficePath\excel.exe " & """" & Me!cboExcel.Value & """"
    Call Shell(stAppName, 1)

Exit_btnRun_Click:
    Exit Sub

Err_btnRun_Click:
    MsgBox Err.Description
    Resume Exit_btnRun_Click
    
End Sub
This opens the file using Excell. I am sure you could modify it to open word. As to how to make it just print w/o opening it, I am not sure, but I bet one of the others knows.

Hope this helps...

Terry M. Hoey
th3856@txmail.sbc.com

Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?
 
Hi Ross,
I've been working on this very problem. Here's the code:

Private Sub Print_Click()
Dim NoOfCopies As Integer, CollatePrint As Boolean
Dim OldPrinter as string
On Error GoTo Print_Click_Err

NoOfCopies = 1
CollatePrint = True
' Open Word application in Memory
If AppWord Is Nothing Then
Set AppWord = CreateObject("Word.Application")
End If

' Open the correct document and print it
Documents.Open FileName:= "c:\my documents\my.doc"
OldPrinter = ActivePrinter
' Replace with your filepath & name
ActivePrinter = "HP Deskjet 500"
ActiveDocument.PrintOut False, , , , , , , NoOfCopies, , , , CollatePrint
ActivePrinter = OldPrinter

' Close the document and quit word
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
AppWord.Quit
Set AppWord = Nothing

Print_Click_end:
Exit Sub
Print_Click_Err:
MsgBox Err.Description, vbOKOnly
Resume Print_Click_end
End Sub

If you only want to print from the default windows printer you can remove the lines refering to ActivePrinter. If you want to print from a named printer (as shown here) must replace the "HP Deskjet 500" with the name of the printer you want to print to (as it's shown in windows). The code changes the printer to this for the print job then changes it back to the windows default afterwards.

You can of course prompt the user for the number of copies and whether they want to collate the printouts. If you want to check the other options on the printout command you can find it in access help.

For this code to work you will need the microsoft word 8.0 object libarary reference set in access.

I Hope this helps, if you have any questions regarding any of the code don't hesitate to ask
Richard
 
Thanks a lot as usual.

A couple of minute alterations and it works a treat.

Much Appreciated.
Ross
 
How fast does this option work? I have found printing documets with word to be very slow (startup), especially since I also populate a couple of fields in the .Dots before printing. Is this your experience?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top