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

Word doc print error #0

Status
Not open for further replies.

jhaganjr

IS-IT--Management
Dec 11, 2002
62
US
Hi,

The ActiveDocument.PrintOut command in the sub below generates an error. What is the easiest way to print a Word doc from within Access (VBA) that involves no merging? Just need to print the doc.

Thanks!

Public Sub PrintWordDoc(ByVal strDocPathAndName As String)
On Error GoTo PrintWordDoc_Error

Dim objWord As New Word.Application
Dim objDoc As Word.Document

objWord.Application.Visible = True
Set objDoc = objWord.Documents.Open(strDocPathAndName)

ActiveDocument.PrintOut
objWord.Application.Documents(1).Close wdDoNotSaveChanges
objWord.Quit

Set objWord = Nothing
Set objDoc = Nothing

PrintWordDoc_Error:
MsgBox "Error #" & Err.Number & " occurred." & Err.Description, vbOKOnly, "Word Error"
objWord.Quit


End Sub
 
Error # 0 usually means no error, try an exit sub in front of the errorhandling... or


[tt]MyExit:
exit sub
PrintWordDoc_Error:
MsgBox "Error #" & Err.Number & " occurred." & Err.Description, vbOKOnly, "Word Error"
' objWord.Quit
Resume MyExit

End Sub[/tt]

Roy-Vidar
 
Replace this:
ActiveDocument.PrintOut
By either this:
objWord.ActiveDocument.PrintOut
Or this:
objDoc.PrintOut

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the responses. I ended up ignoring error number 0. The other syntax still produced the error.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top