Use Automation to Run Word 2000 Mail Merge from Access

R

Rebecca

Basically, I am using the following code in my Access
database to print the records in the query "Customers"
with the mail merge main document "MyMerge.doc" and
sending it directly to the user's default printer. The
user is currently logged in to the database specified in
the OpenDataSource, in this example, the Northwind
database. When this portion of the code runs, the user is
prompted again to enter his username/password for this
database, though he has it open and is working from it.

How can I A) pass the username/password without hard
coding it into the function (a security risk) OR B) have
the "objWord.MailMerge" specify the current database and
therefore not ask for username/password, OR C) just hide
the username/password dialog box (since if you wait long
enough without entering the username/password the merge
prints to the default printer anyway)?

THANKS!!


Function MergeIt()
Dim objWord As Word.Document
Set objWord =
GetObject "C:\MyMerge.doc", "Word.Document")
' Set the mail merge data source as the Northwind
database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\Microsoft " & _
"Office\Office\Samples\Northwind.mdb", _
LinkToSource:=True, _
Connection:="QUERY Customers"
' Print the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
objWord.Application.Quit wdDoNotSaveChanges
End Function
 
C

Cindy M -WordMVP-

Hi Rebecca,

The problem is that the code is creating a DDE connection to
Access. And what you describe is a problem with how Word
handles the DDE during mail merge.

A better choice would be to use ODBC. To get the syntax,
record a macro while connecting to the Access database, and
in the Open Data Source dialog box, activate the "Select
method" checkbox. You'll then get a list of connection
methods - choose ODBC.

If your data source is a query, then you need to click
"Options" and activate "Views" to add the queries to the
list of tables.
Basically, I am using the following code in my Access
database to print the records in the query "Customers"
with the mail merge main document "MyMerge.doc" and
sending it directly to the user's default printer. The
user is currently logged in to the database specified in
the OpenDataSource, in this example, the Northwind
database. When this portion of the code runs, the user is
prompted again to enter his username/password for this
database, though he has it open and is working from it.

How can I A) pass the username/password without hard
coding it into the function (a security risk) OR B) have
the "objWord.MailMerge" specify the current database and
therefore not ask for username/password, OR C) just hide
the username/password dialog box (since if you wait long
enough without entering the username/password the merge
prints to the default printer anyway)?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

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