Word not really closed ?

G

Gina

Hi.

I send some records from access to bookmarks in word
herefore I use
_________________________________________
Set WD = CreateObject("Word.Document")
template = CurrentProject.Path & "\Invoice.dot"
Set DC = Word.Documents.Add(template)
_________________________________________

all works fine .as long as I do only close the actual document in the
upcoming word where my invoice shows up and not the whole word application.
when I close the whole application the next time around when I want to open
word I get an error in the following line
_______________________________________
--> Set DC = Word.Documents.Add(template)
_______________________________________
I get a (Runtime Error: 462) message telling that the
'remote-server-computer doesn't exist or isn't available'

I can press 'Stop' or 'Finish' or 'Debug' (sorry, translated from a German
Version)
If I press 'Debug' the above line --> is highlighted
If I press 'Stop' and use my tool to access word again it works fine.

I have a sub which is called each time after records are sent to word
containing
__________________________________________
Set DC = GetObject(Word.ActiveDocument)
Set DC = Nothing
Set WD = Nothing
__________________________________________

I have checked the task manager and I can see that word is somehow present
as a task that second time but I get this error message

Please anyone an idea of what this could be??
Gina
 
G

Gina

Hi Tony.

tried your suggestion

Set DC = Word.Documents.Add(reVorlage, , , True)
Set DC = WD.Documents.Add(reVorlage, , , True) ... I get an error here

I sthere a possibility to Create an object
Set WD = CreateObject("Word.Application")

and add a document to it in one single step ???
maybe something like

Set WD = Word(CreateObject("Word.Application")).Documents.Add(template)

I am playing around with some syntax ... but don't know at all whether it is
possible

how could I destroy an object created like: Set WD =
CreateObject("Word.Application") ..
setting it to Set WD= Nothing .... doesn't close the word application
underneath

Thanks,
Gina
 
J

Jonathan West

Gina said:
Hi Tony.

tried your suggestion

Set DC = Word.Documents.Add(reVorlage, , , True)
Set DC = WD.Documents.Add(reVorlage, , , True) ... I get an error here

I sthere a possibility to Create an object
Set WD = CreateObject("Word.Application")

and add a document to it in one single step ???
maybe something like

Set WD = Word(CreateObject("Word.Application")).Documents.Add(template)

Take two steps. One extra line of code is not a great hardship, and it gives
you an object variable for the Word application object, which you are likely
to need anyway.
I am playing around with some syntax ... but don't know at all whether it
is
possible

how could I destroy an object created like: Set WD =
CreateObject("Word.Application") ..
setting it to Set WD= Nothing .... doesn't close the word application
underneath

Do this

WD.Quit
Set WD = Nothing
 
T

Tony Jollans

Hi Gina,

To do it in one step you can use GetObject ..

Set myDoc = GetObject("mypath\mydoc.doc")

.. and that will create a Word application if necessary (or use an existing
one if present).

One disadvantage of this is that you don't have direct access to Word - you
have to use wdDoc.Application. You also don't know whether you have picked up
an existing object or created a new one, and so you don't know whether or not
to quit it afterwards.

To destroy the object you must quit the application and empty the object
pointer, so ..

myDoc.Application.Quit
Set myDoc = Nothing

But, beware doing it this way, that you don't lose access to your document
while the application is still active. Do you have a particular reason for
not wanting to instantiate separate Word and Document objects?
 
G

Gina

Hi Jonathan.

tried it but get an error on WD.Quit

object wouldn't support this property or method

Dim WD As Object as public var in the current module

how will I find a way at all around this?? and when ???

Thanks for your answer
Gina
 
T

Tony Jollans

If WD.Quit gives you that error then it is not a Word Application object.

Can you post all relevant code which you are now using.

Enjoy,
Tony
 
G

Gina

Hi Tony.

Thanks ....
myDoc.Application.Quit
Set myDoc = Nothing
tried it but get an error: method or property not available or valid (free
translation from german version).

I would like to see the application word with the active document so that
the user can do some amendments if it is wished - which can be done.
When the document - not the word application - is closed everything seems to
be fine

When the user closes the application instead after some amendments and a
printout or whatever and the next time a new doc is created via access,
I get an error in the Documents.Add(reVorlage) line

No, I don't have a reason for having one single line instead of two ... just
thought that would be a way around to get rid of that open line from my tool
to word underneath.

think I better stop this ... and do something else today!!!! before I go mad
;)

Gina
 
G

Gina

Tony, hi

well I start with

Option Compare Database
Option Explicit
Dim WD As Object
Dim DC As Word.Document

( If I do not create this WD I get an ActiveX error )
code in writeAddress(...) function
____________________________________
Set WD = CreateObject("Word.Document")
reVorlage = CurrentProject.Path & "\Rechnung1.dot"
Set DC = Word.Documents.Add(reVorlage)
.....
.....
____________________________________

at the end of all these diff. functions which write different parts I go
back to the main cmdInvoice
if the user has selected 'open up word' I call releaseWord which contains
________________________________
Public Sub ReleaseWord()
Set DC = GetObject(Word.ActiveDocument)
Set WD = Nothing
Set DC = Nothing
End Sub
_________________________________

when I press the cmdInvoice button next time around (after word has been
totally closed by the user) I get that 'remote-server-computer not existant
or not available'
and if I cklick 'debug' it highlights -->Set DC =
Word.Documents.Add(reVorlage)

if the user has selected 'print it' word and the created doc is invisible,
prints, gets closed and doesn't make any problems
__________________________
Public Sub PrintIt()
Set DC = GetObject(Word.ActiveDocument)
DC.PrintOut Copies:=2
DC.Close SaveChanges:=False
Set DC = Nothing
End Sub
__________________________

Is the active document not added to some sort of collection ..... do I need
to remove it?
Thanks for your help and interest

Gina
 
G

Gina

Jonathan.

Thanks for the links - they are hopefully - or should be - what I need ....
will work through them and hopefully find the reason or my mistake.

sounds all quite complicated, whereas I don't think the thingi I intend to
do should be complicated at all.
I am doing a major mistake here in creating this word object ...
unbelievable.

Thanks again,
Gina
 
T

Tony Jollans

Hi Gina,

You are still not initialising correctly.

Firstly create a Word session:

Set WD = CreateObject("Word.Application")

Then, whenever you do anything with that Word session make sure you use WD.
Do not use Word.anything - use WD.anything instead.

Now create a document:

Set DC = WD.Documents.Add(yourtemplate)

When you reference the document use DC. When you reference Word use WD. Do
not use Selection on its own.

WHen you're done, do:

DC.Close
WD.Quit

Set DC = Nothing
Set WD = Nothing


Enjoy,
Tony
 
G

Gina

Solved it
please see
created a new word application object and referred to when
GetObject(wrd.ActiveDocument)
can quit the app with wrd.quit
set wrd = Nothing

just have to try it again ....
nearly two days I was suffering
but now
Thanks to you
Gina :))
 
G

Gina

Thanks Tony

exactly that solved my problem now
create a ref to the application itself rather than a document

solved ... goodneess deary me - I am so glad!!!

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