Word Automation opening datasource multiple times

T

tnbfyles

We are using Visual C++ 6.0 with the msword8 automation added from the
type library. It works well for us so far. But...

We have just noticed that when we use a MailMerge object, the data
source is opened mulitple times.

e.g. Our data source is a stored procedure (in Sybase) that returns a
record set that will be merged with our Word document. The stored
procedure also inserts a record into a logging table to indicate when
it was called.

When we do the following:

merge.OpenDataSource(
"",
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
covOptional,
COleVariant(connectionString, VT_BSTR),
COleVariant(queryPart1, VT_BSTR),
COleVariant(queryPart2, VT_BSTR));

The stored procedure is called twice (our log table has two records
inserted).

When we do this:

merge.Execute(covFalse);

We get another log entry (the procedure was called again)

And finally, when we close our document:

testDoc.Close(covFalse, covOptional, covOptional);
(testDoc is a _Document object)

The stored procedure is called two more times.

The merge itself works perfectly, and we have been using it for two
years now without a problem, but we just noticed this problem
accidentally when we added the logging feature.

This worries me that the stored procedure is called five times for a
single document merge, particularly from a performance perspective.

Is this working as designed? Is there a way to change this behaviour?


Thanks for any help

Tony.
 
C

Cindy M -WordMVP-

The merge itself works perfectly, and we have been using it for two
years now without a problem, but we just noticed this problem
accidentally when we added the logging feature.

This worries me that the stored procedure is called five times for a
single document merge, particularly from a performance perspective.

Is this working as designed? Is there a way to change this behaviour?
Yes. No.

Actually, I think you'd find that, if the use were viewing the records,
and flipping through them, there'd be a call to the data source each
time.

In the "Office world", it's not uncommon for users who maintain their
own data sources (Excel table, for example) to edit those data source
during the course of preparing to merge. So Word does call back to the
data source at "every opportunity", thus making sure that the data the
user is seeing is always as up-to-date as possible.

When discussing Word, and especially mail merge, one always has to keep
in mind that the core of the application was designed some twenty years
ago. Back then, dynamic network data sources were rare beasts; most
connections were local. So, while newer versions of Word are able to
connect using an OLE DB provider, they don't use the provider the way it
was designed to be used (with ADO, client-side datasets, etc.).

the only thing you could possibly do would be to put a programming layer
in between that would get the data then save it to a file, locally, so
that the mail merge is not connected to the data source via the network.
Or program the entire thing and not use mail merge at all.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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