Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Dec 2002
    Location
    Kitchener, Ontario, Canada
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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

  3. #3
    4 Star Lounger
    Join Date
    Dec 2002
    Location
    Kitchener, Ontario, Canada
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •