Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Word not really closed ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gina - 09 Mar 2005 18:51 GMT
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
Tony Jollans - 10 Mar 2005 00:53 GMT
This is due to implicit instantiation. You are using a Word object that you
have not set up.

See http://support.microsoft.com/default.aspx?scid=kb;en-us;189618

Change to something like:

   Set WD = CreateObject("Word.Application")
   template = CurrentProject.Path & "\Invoice.dot"
   Set DC = WD.Documents.Add(template)

Enjoy,
Tony

> Hi.
>
[quoted text clipped - 34 lines]
> Please anyone an idea of what this could be??
> Gina
Gina - 10 Mar 2005 08:27 GMT
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

> This is due to implicit instantiation. You are using a Word object that you
> have not set up.
[quoted text clipped - 48 lines]
> > Please anyone an idea of what this could be??
> > Gina
Jonathan West - 10 Mar 2005 10:06 GMT
> Hi Tony.
>
[quoted text clipped - 10 lines]
>
> 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
[quoted text clipped - 4 lines]
> setting it to Set WD= Nothing .... doesn't close the word application
> underneath

Do this

WD.Quit
Set WD = Nothing

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Gina - 10 Mar 2005 11:28 GMT
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

> > Hi Tony.
> >
[quoted text clipped - 28 lines]
> WD.Quit
> Set WD = Nothing
Jonathan West - 10 Mar 2005 11:42 GMT
Take a look at these two articles, and see what you are doing that is
different

Control Word from Excel
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm

Early vs. Late Binding
http://www.word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Hi Jonathan.
>
[quoted text clipped - 44 lines]
>> WD.Quit
>> Set WD = Nothing
Gina - 10 Mar 2005 12:39 GMT
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

> Take a look at these two articles, and see what you are doing that is
> different
[quoted text clipped - 32 lines]
> >> >
> >> > 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
[quoted text clipped - 16 lines]
> >> WD.Quit
> >> Set WD = Nothing
Tony Jollans - 10 Mar 2005 11:49 GMT
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

> Hi Jonathan.
>
[quoted text clipped - 44 lines]
> > WD.Quit
> > Set WD = Nothing
Gina - 10 Mar 2005 12:27 GMT
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

> If WD.Quit gives you that error then it is not a Word Application object.
>
[quoted text clipped - 30 lines]
> > > >
> > > > 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
[quoted text clipped - 16 lines]
> > > WD.Quit
> > > Set WD = Nothing
Tony Jollans - 10 Mar 2005 13:33 GMT
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
Gina - 10 Mar 2005 13:39 GMT
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
> Hi Gina,
>
[quoted text clipped - 24 lines]
> Enjoy,
> Tony
Tony Jollans - 10 Mar 2005 10:31 GMT
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?

> Hi Tony.
>
[quoted text clipped - 79 lines]
> > > Please anyone an idea of what this could be??
> > > Gina
Gina - 10 Mar 2005 11:49 GMT
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

> Hi Gina,
>
[quoted text clipped - 103 lines]
> > > > Please anyone an idea of what this could be??
> > > > Gina
Gina - 10 Mar 2005 13:37 GMT
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 :))

> Hi.
>
[quoted text clipped - 34 lines]
> Please anyone an idea of what this could be??
> Gina

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.