• Word won’t print at other pc (Access/Word 97)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Word won’t print at other pc (Access/Word 97)

    Author
    Topic
    #422007

    Valuable members of this board,

    I use Access VBA automation for printing a few thousands of Word documents.
    You find the database attached + a separate txt-file with the procedure (module – procedure FindReplace)): I’ve put ‘=========== lines before & after the code lines in question.
    This worked great on my pc untill I got a ‘blue screen’ several times… Having no time to figure out why, I “quickly”‘ turned to a collegue’s pc, installed the necessary driver, moved the Access database over there, repaired & compacted, checked the VBA references.

    Problem: the procedure runs without an error but the Word print command doesn’t execute while the Word instance (invisible) doesn’t close, so remains open.
    What may have gone wrong?

    Viewing 0 reply threads
    Author
    Replies
    • #960865

      The procedure has several problems:

      – You set “On Error Resume Next” at the beginning; this is needed to avoid problems if Word is not running, but you should set “On Error GoTo 0” or even better “On Error GoTo ErrorHandler” where ErrorHandler is a label after setting appWord. The way it is now, you’ll never be warned if an error occurs.

      – You repeatedly use GetObject / New Word.Application within the loop. You already set appWord before the loop, so there is no need to do it within the loop.

      – You also shouldn’t set appWord to Nothing within the loop, but afterwards.

      – You should quit Word at the end if you started it at the beginning:

      Dim blnStartWord As Boolean
      Set appWord = GetObject(, “Word.Application”)
      If Err = 429 Then
      Set appWord = New Word.Application
      blnStartWord = True
      End If
      On Error Goto 0

      At the end:

      If blnStartWord = True Then
      appWord.Quit
      End If
      Set appWord = Nothing

    Viewing 0 reply threads
    Reply To: Word won’t print at other pc (Access/Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: