473,387 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

WinWord Mail Merge

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
3 2235
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: William Wisnieski | last post by:
Hi Everyone, Access 2000 I have some code behind a button that performs a word merge with a query data source. The merge works fine. But what I'd like to do somehow is after the merge is...
2
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible....
1
by: Lisa | last post by:
I have a query named QryDept where one of the fields is DeptID. The query is used for the data source of a mail merge letter. I would like to control which department is to get the mail merge...
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
3
by: James | last post by:
Howdy. I'm having difficulty getting winword.exe processes to die on our development server when using SET objWord = CreateObject("word.application") from an .ASP page. This problem exists on...
6
by: crealesmith | last post by:
Firstly, I have no problem with mail merging to Word, VB code for that works perfectly. On one mail merge I need to merge 15 fields of data that are from 3 seperate records. The 3 records are all...
7
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to follow a mail merging example in C#.Net that I got from: http://support.microsoft.com/default.aspx/kb/301659 and in one the methods: Word.Application wrdApp; Word._Document...
1
by: ddeterman | last post by:
I am extremely new to C#, so please respond using small words. :-) I am working on a client/server application which creates a word document and attaches it to an e-mail. Once the e-mail is sent, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.