• Runtime error 642 with Word automation

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Runtime error 642 with Word automation

    Author
    Topic
    #462622

    I have the module from one of my previous posts working, but I am still having trouble with runtime error 642 when I try to run the module more than once from within the same database session. A little history:

    Previously I had this as two separate subs and the second one was frequently hanging. As a workaround, I combined the two and used the same instance of New Word.Application rather than two instances. I played around with various configurations and was still running into this error. With everything combined into one sub, it runs fine the first time, but stalls if I try to rerun it. I know it has something to do with the New keyword but haven’t been able to find a solution. The second time around, when it fails, I always find a hidden instance of Word in the task manager which wasn’t there before I start running it the second time.

    I assume I have something not quite right in the syntax or in killing the Word App.

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1178113

      When using Automation, you must take great care to refer ALL objects in the automated application directly or indirectly to the application object, in this case wrdApp.

      For example,

      wrdTbl.Cell(4, 2).Range.Text = intTot

      is correct because wrdTbl is derived from wrdDoc and wrdDoc is derived from wrdApp.

      But you use ActiveWindow and Selection several times without reference to wrdApp, for example

      If ActiveWindow.View.SplitSpecial wdPaneNone Then

      You have wrapped this section of the code in With wrdApp … End With but that doesn’t help. You should use .ActiveWindow and .Selection within this block, for example

      If .ActiveWindow.View.SplitSpecial wdPaneNone Then

      • #1178608

        I finally had a chance to look at this tonight and it is all working properly once I got the dots in place. Many thanks.

    Viewing 0 reply threads
    Reply To: Runtime error 642 with Word automation

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

    Your information: