Printing Word Doc from Access

M

Mark

We are using Office97 running under Windows2000.

The Users run an Access97 application that I developed.
At some point they press a button that prints a Word97
document on the Colour printer.

Until quite recently this used to work with no problems,
however when they now press the print button the system
freezes.

I have investigated this problem and found the application
is freezing due to a Word "Save As..." dialog box being
open waiting for the user. Unfortunately the user cannot
see the dialog box as Words visibility is set to false.

Someone said the problem is due to a Windows Update and
that I have to change the way I am printing the document
to get around this problem. Is this correct?

The code I am using to print the Word document is as
follows;

Private Sub cmdPrintFactSheet_Click()
' subRoutine to Print the Fact Sheet.

Dim blnRes As Boolean

blnRes = printFactSheet(Me.DocNo)

If blnRes Then
MsgBox " Fact Sheet sent to Printer"
End If

End Sub

Function printFactSheet(DocNo As Integer) As Boolean
' Print the Fact Sheet

Dim TmpName As String
Dim strActivePrinter As String
Dim strSQL As String

On Error GoTo Err_printFactSheet
DoCmd.Hourglass True

strSQL = "Select HFactSheet from myTable WHERE
DocNo=" & DocNo
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

TmpName = "M:/Winword/Fact Sheets/"
TmpName = TmpName & rs("HFactSheet") & ".doc"

Set WApp = CreateObject("Word.Application")
On Error GoTo Err_WordApp
With WApp
' .Visible = True
.Visible = False
.Documents.Open TmpName
End With

printFactSheet = sendDocToColourPrinter(WApp)

If printFactSheet Then
MsgBox "Fact Sheet sent to colour printer"
Else
MsgBox "Could not print the Fact Sheet"
End If

Exit_WordApp:
' WApp.ActiveDocument.Close
WApp.Quit
Set WApp = Nothing

Exit_printFactSheet:
DoCmd.Hourglass False
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

Exit Function

Err_WordApp:
MsgBox Err.Description
printFactSheet = False
Resume Exit_WordApp

Err_printFactSheet:
MsgBox Err.Description
printFactSheet = False
Resume Exit_printFactSheet

End Function

Function sendDocToColourPrinter(WApp As Object) As Boolean
' Send the active document to the "Colour Deskjet"
Printer (HPDJ8600)
'
Dim strActivePrinter As String

sendDocToColourPrinter = False
On Error GoTo Err_sendDocToColourPrinter

' Get the current Active Printer.
strActivePrinter = WApp.ActivePrinter

' Change to the Default Printer
' WApp.ActivePrinter = "HP LaserJet 6L (PCL)"
' WApp.ActivePrinter = "Default Printer"
WApp.ActivePrinter = "HP DeskJet 840C Series"

' Print the active document.
WApp.ActiveDocument.PrintOut

' Change back to the original printer.
WApp.ActivePrinter = strActivePrinter

sendDocToColourPrinter = True

Err_sendDocToColourPrinter:

End Function

Any suggestions as to what I am doing wrong?
TIA for any help,

Mark.
 
H

Howard Kaikow

The problem is you are issuing a CLOSE for the Word document without either
having previously saved the doc or telling Word to not save the document.

Take a look at the SaveChanges keyword for the Close method in Word.
 
M

Mike Walker

ActiveDocument.Close wdDoNotSaveChanges

Would be the command to issue as the print command has updated and made the
document dirty hence prompt to save.

Rgds

Mike Walker
(Reply via NG)
 

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