word vba printing problem

J

jarrah

I have a problem with printing to a network printer using
vb6 to update a template with vba code. The program opens
the template document , enters some text using bookmarks
then opens the print preview screen. The user can then
print or exit the document. If the user chooses to print
when there is a large amount of network traffic an
application busy error occurs (switch to .....). I think
the problem is that the program doesn't have enough time
to print before it tries to shut the word application
down. I have tried putting timouts in but still has the
same problem. Im not sure if the code is wrong or what???

Any ideas would be very much appreciated

my setup: vb6 sp5, win2k sp3

Here is the relevant code.

----------------------------------------------------------
--
Set oWord.App = CreateObject("Word.Application")

If oWord.App Is Nothing Then
Set oWord.App = New Word.Application
If oWord.App Is Nothing Then
MsgBox "Sorry, Microsoft Word 2000 is required for this
report"

End If
End If

With oWord.App
..Visible = False
'Opens ColdEnd Template file

..Documents.Open (clsMyAppPath & "\ColdEnd.DOC")

--------------------------------------
"document updated here via bookmaks"
--------------------------------------

If .Application.PrintPreview = False Then
..ActiveDocument.PrintPreview
End If
..Visible = True
While .Application.PrintPreview = True
Do While .Application.BackgroundPrintingStatus > 0
'Sleep 1000
Loop
Wend
..Visible = False

DocName = clsMyAppPath & "\temp\" & "Temp_" &
CurrentRun.RunID & ".doc"

..Application.ActiveDocument.SaveAs FileName:=DocName
..Documents.Close
..Quit
End With

Set oWord.App = Nothing
Set CurrentDepartment = Nothing
Set ComparatorDepartment = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top