Merge a Query from within Access to a Word Mail Merge Main Doc

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
 
T

Tim Ferguson

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)?

I have to confess that I never understood the point of trying to drive a
Word mailmerge from inside an Access database. Is there anything that a
word doc will do that an Access report won't do quicker and with less
hassle? I understand that Word docs are quicker and easier to develop, but
in that case the whole process begins and ends with Word and does not have
to involve the Access GUI at all.

Something about rods and backs springs to mind...


HTH


Tim F
 
R

Rebecca

You bring up good points. In this situation, the user
selects records in an Access front-end, then creates 5 to
6 different reports (currently 1 Access report and 5 Word
mail merge docs) with the records. So, as the user starts
with Access to select the records, and then selects the
reports to print in Access, the user doesn't know he is
using Word since the code opens Word invisibly, and then
the user ends with Access.

OK. So I could make the remaining docs into Access reports
(and I think that I might, since that would solve my
problem), but the one that I currently have in there,
isn't the best that it could be, and has left me
unimpressed with Access reports.

My report is a letter. Using the Northwind example below,
it would be a letter to the sales force, listing their
customers' names. The letter has body text above and below
the listing of names. Since there are SO many names, the
report detail section uses 3 columns in the report's page
set-up. Since I don't want the body text below to be in
columns too, I put that text in the page footer. But,
here's the CATCH: that text is fixed on the page in the
same location, no matter if there is one name or 20 names.

How do I get it to move up against the detail section when
the 3 column detail section shrinks?

I think I'll post this in the reports section too.
 
T

Tim Ferguson

How do I get it to move up against the detail section when
the 3 column detail section shrinks?
Off the top of my head: put it in a group footer (even if there is only one
group?).
I think I'll post this in the reports section too.
Good idea.. :)


B wishes


Tim F
 

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