By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,806 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,806 IT Pros & Developers. It's quick & easy.

WinWord Mail Merge

P: n/a
We are performing a mail merge from our Microsoft Access application.
When the application starts, it attempts to create a word object using
late binding via a call to CreateObject. The idea was that this
object would remain hidden and we would perform merges to it as
necessary. I have come across two problems. If the user starts our
application and then later invokes Microsoft Word, Word doesn't bother
to start another instance of itself. It just happily makes the
instance we had created visible instead of invisible. Well, I
thought, I will just create another instance if this happens. I can
easily iterate through all instances of Microsoft Word and determine
if the window is visible or invisible, but I cannot obtain a reference
back to these instances. Is the only way to obtain a reference back
to Microsoft Word via a call to GetObject(), or is there another,
trickier way that I am unaware of? I wouldn't have a problem with
GetObject, but for the fact it will return a random reference back to
one of the instances of Word. I can't guarantee that the reference it
returns will be to an instance of Word that is invisible. Any
suggestions? Thanks.

Vincent

May 21 '07 #1
Share this Question
Share on Google+
3 Replies

P: n/a
if you keep a global variable references to the instance of word you
created, then
how can a different instance be returned when you automaton?

Either you destroy the instance you make, and create a NEW ONE each time.

If you looking to keep control of the instance you made, then don't destroy
the reference you made...

I can't see how it is possible you loose control of that instance you
made....

Dim wordApp As Object ' running instance of word

Set wordApp = CreateObject("Word.Application")

Simple ensure that wordApp never goes out of scope (that means it needs to
be a public global variable declared in a standard code module, not local to
your code rouinte).

Once you create that instance, never destroy it. That should insure that
your automaton code will return a different, or non user running instance of
word.

If you let wordApp go out of scope, and then use:

Set wordApp = GetObject(, "Word.Application")

I always do the above (to prevent loading an additional copy of word).
However, if you use the above syntax to return word, then of couse wordApp
will be one of any random instance of word running (you save re-loading of
word..but, you have NO CONTORL as to what instance you running).

So, use the first syntax I suggested, and create wordApp ONCE IN YOUR
code..and then ALWAYS use that instance you made.

It will not matter if other additional copies of word are launched (or
closed) by the user, you should be albe to retain contorl of that instance
you made.

So, create your running instance of word, and never let that variable go out
of scope.

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
May 21 '07 #2

P: n/a
Obviously, you have been spoiled enough to work with code that
contains error trapping everywhere. I am not so fortunate. If an
error occurs, it is possible to lose the value of these global
variables. It is this situation that I am worried about.

Vincent

On May 21, 7:41 pm, "Albert D. Kallal" <PleaseNOOOsPAMmkal...@msn.com>
wrote:
if you keep a global variable references to the instance of word you
created, then
how can a different instance be returned when you automaton?

Either you destroy the instance you make, and create a NEW ONE each time.

If you looking to keep control of the instance you made, then don't destroy
the reference you made...

I can't see how it is possible you loose control of that instance you
made....

Dim wordApp As Object ' running instance of word

Set wordApp = CreateObject("Word.Application")

Simple ensure that wordApp never goes out of scope (that means it needs to
be a public global variable declared in a standard code module, not local to
your code rouinte).

Once you create that instance, never destroy it. That should insure that
your automaton code will return a different, or non user running instance of
word.

If you let wordApp go out of scope, and then use:

Set wordApp = GetObject(, "Word.Application")

I always do the above (to prevent loading an additional copy of word).
However, if you use the above syntax to return word, then of couse wordApp
will be one of any random instance of word running (you save re-loading of
word..but, you have NO CONTORL as to what instance you running).

So, use the first syntax I suggested, and create wordApp ONCE IN YOUR
code..and then ALWAYS use that instance you made.

It will not matter if other additional copies of word are launched (or
closed) by the user, you should be albe to retain contorl of that instance
you made.

So, create your running instance of word, and never let that variable go out
of scope.

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKal...@msn.com

May 21 '07 #3

P: n/a
"Vincent" <an**********@verizon.netwrote in message
news:11**********************@x18g2000prd.googlegr oups.com...
Obviously, you have been spoiled enough to work with code that
contains error trapping everywhere. I am not so fortunate. If an
error occurs, it is possible to lose the value of these global
variables. It is this situation that I am worried about.
Ah, but then all you need to do is distribute a mde, as a mde is for
"production" code. In a mde, un-handled errors do not re-set all vars...

of course, if you use a mde, you likey have to be running a split database
if you every are going to issue udpates or bug fixes.
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
May 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.