Closing desktop opened word wants to close embedded word object

I have an Access program that I am using to build Word documents. If while the document is being built (which can be lengthy) I open Word on the desktop and then close it, Word asks me if I want to save the doc that is being built by the program. Of course if I say yes/no then the program gets the rug pulled out form underneath it. I can say cancel and things will go on their merry way but then there is this blank Word sitting there. This is going to confuse the user.

I thought that I was creating a separate instance of Word programatically but apparently not. Is there a way to prevent the desktop Word from bothering the embedded object.

Here is a code snippt

Dim adoc as object

dim wdobj as word.document

set adoc = CreateObject("word.application")

set wdobj = adoc.documents.add(:Template:=x.dot, NewTemplate:=False,DocumentType:=0)

...add to wdobj

wdobj.saveas filename

set wdobj = nothing

adoc.quit

set adoc = nothing

Thanks,

Rick



Answer this question

Closing desktop opened word wants to close embedded word object

  • tk_vb

    Figured it out:

    instead of: set adoc = CreateObject("word.application") use set adoc = new word.application and a new seperate instance of word is created.


  • Closing desktop opened word wants to close embedded word object