From Access To Word

G

Gina

Hi.

posted in a different group ... probably the wrong one
I send some retrieved records from access to word

Set WD = CreateObject("Word.Document")
templ = CurrentProject.Path & "\Invoice.dot"

Set DC = Word.Documents.Add(templ , , , True)
......
......

Set DC = Nothing

all works fine .
If I want word to open, show the doc, print and close it and do the same job
the second time, I get the answer that the
remote server computer doesn't exist or isn't available (Runtime Error: 462)
I just work on a standalone pc

Think I may not close the word application properly or the template what do
I have to do with the WD Object ?? is it word application?

Thanks for any idea, how I could solve this
Gina
 
J

John Nurick

Hi Gina,

Why are you first creating a new Word document with
Set WD = CreateObject("Word.Document") and then creating another with
Set DC = Word.Documents.Add(templ , , , True)
?

What are you doing with WD?
How are you closing the documents and the Word application?
 
G

Gina

Hi John.

Thanks for your answer.

well, I am new to this stuff here and was following an example piece of code

Is it correct that I only have to Set DC = Word.Documents.Add(templ , , ,
True)
in order to create that line to word to send my records through ?

and forget about Set WD = CreateObject("Word.Document") totally ??

how would I be able to destroy that WD ??

I was struggeling the whole day yesterday about this silly thing - couldn't
figure it out.

Thanks again,
Gina
 
J

John Nurick

I'd do something like this:

Dim oWord As Word.Application
Dim oDoc As Word.Document

Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add(TemplateName, ...)

'Do stuff with oDoc
...
'maybe save it
oDoc.SaveAs FileSpec, ...

'close it
oDoc.Close False
Set oDoc = Nothing

'close Word
oWord.Quit
Set oWord = Nothing



Hi John.

Thanks for your answer.

well, I am new to this stuff here and was following an example piece of code

Is it correct that I only have to Set DC = Word.Documents.Add(templ , , ,
True)
in order to create that line to word to send my records through ?

and forget about Set WD = CreateObject("Word.Document") totally ??

how would I be able to destroy that WD ??

I was struggeling the whole day yesterday about this silly thing - couldn't
figure it out.

Thanks again,
Gina
 

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