View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Detach or change SQL data source for Word template, and other Qs

I suggest you use Google groups to have a good look through this newsgroup -
some of the answers to your questions are repeated many times (but others
are not).

be a button in the toolbar called "Merge" that prompted the user to type
in a


In which application? Access or Word?

When I open the Word templates I get warnings that some SQL is about to be
executed - that's OK, but I can't find that SQL in the VBA editor, or any
of
the document properties for the templates. Where should I be looking? I'd
like to change the SQL, or delete it -- how can I do that?


This prompt is displayed every time you open a Mail Merge Main document
connected to a data source (well, there may be circumstances in which it is
not displayed, but they are oddities). The prompt can be suppressed by
changing the Windows registry - see

http://support.microsoft.com/default...b;en-us;825765

The "SQL" is created when the user connects the mail merge main document to
a data source, and is saved with the document and re-issued when it is
opened, along with a suitable connection string etc. You can't really delete
it, since there is always some "SQL" - that's simply how Word codifies its
queries. The connection may have been made programmatically using Word's
OpenDataSource method, and the SQL may have been modified by changing
ActiveDocument.MailMerge.DataSource.QueryString. You can find out (roughly)
what Word is trying to issue, after it has successfully opened the data
source, by printing the values of

ActiveDocument.MailMerge.DataSource.Name
ActiveDocument.MailMerge.DataSource.ConnectString
ActiveDocument.MailMerge.DataSource.QueryString

No data is inserted in to the templates after I open them. Why is SQL
being
executed for the template? Surely the data normally needs to be retrieved
for
the actual documents, or when I do the merge?


When you create a new document based on a template that has a data source
attached, Word tries to connect tot he data source for both the template and
the new document. It is AFAIK trying to check the connection information,
but is also trying to retrieve data to be used in the merge preview and to
let the user select records using Word's Select Recipients dialog box.

As far as I can tell, in Word 2000 and earlier, Word did not try to open one
connection for the document and another for the attached template, but in
Word 2002/2003 it generally does so, and that can cause problems if the data
source is not a multi-user data source, or is opened using a method that
insists on exclusive access. Frankly, you don't get much control over the
exclusivity, read-only-ness of a Word connection to a data source using
OpenDataSource and its connection string - in some cases, Word appears just
to use whatever settings it likes in that area.

Additionally, the SQL described in the warning is a search for a
particular
row from Access. If I click the "Merge to new document" button while
editing
the template, then every entry in the table is merged, so what was the
point
of the SQL?


It sounds like you are in efect creating a new mailmerge main document with
a new data source at this point.

My goal is to allow the user to create a form letter based on a single
entry
in the DB with as few clicks as possible. I think that I need to start by
getting some good defaults in the template (like the correct data source),
carrying that default over to the docs created from the template, and also
having the Merge toolbar visible to the user when they are looking at a
Merge
document.


If your application is fairly simple, i.e. you just need to stuff a few
values into Word from a selected recod in Access, I would avoid MailMerge
altogether as it's far too complicated. it's probably better to follow e.g.

http://support.microsoft.com/kb/210271

(although I've just encountered someone with problems implementing that so
cannot be sure it will work for you)

Personally I do not have a good "pattern" you could follow, so assuming that
is what you need, I suggest you post again eithe rhere or in a suitable
Access conf. and ask for precisely that.

Peter Jamieson


"SJMac" wrote in message
...
Hello,

I'm an app programmer looking at a Word and Access Mail Merge issue - lost
and confused!

I've been asked to look at an Access DB application that has a custom
input
form with a big table behind it. Related to that are a collection of Word
templates for form letters with lots of Merge Fields in.

The templates were originally created and used with Word 2000, but the
current environment is Office XP/Word 2002. I've been told that there used
to
be a button in the toolbar called "Merge" that prompted the user to type
in a
case number to identify the DB row to merge, but that is missing without
trace right now.

When I open the Word templates I get warnings that some SQL is about to be
executed - that's OK, but I can't find that SQL in the VBA editor, or any
of
the document properties for the templates. Where should I be looking? I'd
like to change the SQL, or delete it -- how can I do that?

No data is inserted in to the templates after I open them. Why is SQL
being
executed for the template? Surely the data normally needs to be retrieved
for
the actual documents, or when I do the merge?

Additionally, the SQL described in the warning is a search for a
particular
row from Access. If I click the "Merge to new document" button while
editing
the template, then every entry in the table is merged, so what was the
point
of the SQL?

When I create a new document based on a template, there does not appear to
be any data source defined, and the Merge toolbar is hidden, so I need to
do
a few clicks to get that on the screen -- how can I keep that on the
screen
by default?

My goal is to allow the user to create a form letter based on a single
entry
in the DB with as few clicks as possible. I think that I need to start by
getting some good defaults in the template (like the correct data source),
carrying that default over to the docs created from the template, and also
having the Merge toolbar visible to the user when they are looking at a
Merge
document.

Any clues will be gratefully recieved ...

Steven