closing a Word Document in Access

B

Beth

I have opened a Word doc, filled in the data from Access, and merged to new
document. I now want to close the original doc. I got the following from the
MSDN site:
Documents("Document1").Close SaveChanges:=wdDoNotSaveChanges

This only works once per run. If I open a second doc( i.e execute the
routine again), when it get to this line I get error message:
"The remote server machine does not exist or is unavailable"

******There is no remote server machine. I have one PC!!******

I have the entire path expressed in the filename (actually I tried both ways).
This is the case for all of my versions of Access and Word (2000,2002, and
2003).

I can't use app.activeDocument.close because it will not close the right doc
( my new merged doc Letters1 is the active doc.)

any suggestions?

Also I am using DDE. which seems to be somewhat unstable. Sometimes it works
and sometimes it prompts with several dialogs to define login,
connectivity....

ODBC seems to be alot more stable but does not support memos and dates.


any suggestions on either of these items would be most appreciated

Thanks,

Beth
 
S

strive4peace

Hi Beth,

are you closing and releasing your object variables at the end of the
procedure? Unlike regular variables, object variables need to be
specifically released or an instance of Word will stay open.

if you are running code from Access, you need to preface your commands
with the object variable for the Word application (which I am sure you
must be doing or it wouldn't work right the first time either).

Can you post your code?


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
B

Beth

yes. I am setting the object var to nothing at the end.

However, I was not using the obj var to preface the command, as the example
didn't have it that way. I put the obj var on the command and it is working
now.
WordDoc.Applications.Documents("Document1").Close
SaveChanges:=wdDoNotSaveChanges

Strangely, it did work the first time every time I ran it without the var.
go figure???

Thank you so much!

Beth
 
S

strive4peace

you're welcome, Beth ;) happy to help

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top