[AccessD] word automation not printing

Mitsules, Mark S. (Newport News) Mark.Mitsules at ngc.com
Tue Mar 2 07:41:10 CST 2004


Gustav set me on the right track a few years ago with this problem.  ...and
I quote "Printing is VERY much faster if background printing is off."  See
example courtesy of Gustav:)


Mark

Function PrintDoc(ByVal strFileName As String) As Boolean
' Print Word document from within Access.
' 2000-05-27. Gustav Brock. Cactus Data ApS.
' Example: ? WordDocPrint("C:\Temp\Products.doc")
  Dim appWord As Word.Application
  Dim booPrintBackground As Boolean
  Dim WordDocPrint As Boolean

  Set appWord = New Word.Application
  'Debug.Print "- activated"

  With appWord
    .Documents.Open strFileName
    'Debug.Print "- opened"

    ' Store background printing option.
    booPrintBackground = .Options.PrintBackground
    If booPrintBackground = True Then
      ' Printing is VERY much faster if background printing is off.
      .Options.PrintBackground = False
    End If

    .ActiveDocument.PrintOut
    ' Not needed if background printing option is off.
    While .BackgroundPrintingStatus > 0
      'Debug.Print "- printing"
      StatusBar = .BackgroundPrintingStatus & " print jobs are queued up"
      DoEvents
    Wend
    ' -----------------------------------------------
    'Debug.Print "- printed"

    ' Restore background printing option.
    If booPrintBackground = True Then
      .Options.PrintBackground = True
    End If
    .ActiveDocument.Close
    'Debug.Print "- closed"

    .Quit
    'Debug.Print "- quit"
  End With

  Set appWord = Nothing

  WordDocPrint = True

End Function











-----Original Message-----
From: John W. Colby [mailto:jwcolby at colbyconsulting.com] 
Sent: Tuesday, March 02, 2004 8:33 AM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] word automation not printing


A DoEvents thingie?  Getting kinda technical aren't you?

;-)

John W. Colby
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of S D
Sent: Tuesday, March 02, 2004 8:21 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] word automation not printing


you could try a timer event...wait a couple of seconds before quiting...
Isn't it possible to use a doevents thingy?

HTH
Sander

"John W. Colby" <jwcolby at colbyconsulting.com> wrote:
Folks,

I am using the following code to print an existing document using word
automation. If I leave out the msgbox statement the document doesn't print.
It's almost as if the close happens before the print manages to get the
document out of word and into the print queue. Has anyone seen this? Any
suggestions? The "Press any key" solution is unprofessional to say the
least.

Function PrintWordDoc(strFilePath As String, strFileName As String, intCnt
As Integer) As Boolean On Error GoTo Err_PrintWordDoc Dim AppWord As
Word.Application Dim lDoc As Word.Document Set AppWord =
CreateObject("Word.Application") With AppWord .Visible = True
.Documents.Open (strFilePath & strFileName) Set lDoc =
.Documents(strFileName) lDoc.PrintOut , , , , , , , intCnt

msgbox "Press any key to continue"

.Quit savechanges:=False
End With
PrintWordDoc = True
Exit_PrintWordDoc:
On Error Resume Next
Set lDoc = Nothing
Set AppWord = Nothing
Exit Function
Err_PrintWordDoc:
MsgBox Err.Description, , "Error in Sub basMailMerge.PrintWordDoc" Resume
Exit_PrintWordDoc Resume 0 '.FOR TROUBLESHOOTING End Function



John W. Colby
www.ColbyConsulting.com


--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



---------------------------------
Do you Yahoo!?
Yahoo! Search - Find what youre looking for faster.
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list