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

VBA PRINTOUT ERRORS

Status
Not open for further replies.

bradmaunsell

Programmer
May 8, 2001
156
US
I fumbling with a WORD subroutine and have a printing problem using the PRINTOUT method.

Windows 2000, Access 97 Word 2000

I push a button on an Access 97 form to run a subroutine that opens a Word Template and then is suppose to print the document and close Word and return to Access 97.

The template is opened and displayed but stops with an error dialog box message saying:

"Word is currently printing. Quitting Word will cancel all pending print jobs. Do you want to quit Word? (Yes or No)

If I answer NO the system prints as requested and Word stays open.

If I answer YES, Word closes and I am retured to my Access 97 form (without printing).

Here is my code:



Sub CreateFPE101()

CreateNewWordInstance

strTemplate = "FPE101_GeneralChangeEndorsement.dot"
CreateWordDocument (strTemplate)

oWord.Application.ActiveDocument.PrintOut

oWord.Application.Quit
Set oWord = Nothing

End Sub



Public Sub CreateNewWordInstance()
' Requires Microsoft Word 9.0 Object Library

On Error Resume Next
Set oWord = GetObject(, "Word.Application") 'Try to get an open word object
If Err.Number = 429 Or Err.Number = 0 Then 'No word objects currently open so create one
Set oWord = CreateObject("Word.Application")
ElseIf Err.Number <> 0 Then
MsgBox &quot;Ooops!! Found an open Word instance!! Error: &quot; & Err.Description
Exit Sub
End If

oWord.Visible = True
oWord.Activate 'Bring word application to top

End Sub



Public Sub CreateWordDocument(strTemplateName)

pathAddNewWordDoc = pathGetWordTemplate & &quot;\&quot; & strTemplateName

oWord.Documents.Add pathAddNewWordDoc, NewTemplate:=False, DocumentType:=0 'Open new Word document using .dot template

End Sub



I have temporarily removed the population routines to simplify the trouble shooting process.

Thanks for any help.
Brad
South Burlington, Vermont
 
I continued fumbling and discovered setting background to FALSE fixed this problem.

Brad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top