Mail Merge from a command button

dcjones

Dereck
Local time
Today, 13:00
Joined
Mar 10, 2004
Messages
108
Hi All,

I have spent the last 2 hours reading post concerning mail merge but have not been able to find the anwser to my question.

I have a Button on my Form that currently (when clicked) executes a macro which in turn does that following tasks:

OpenQuery, Query1.
RunApp, winword "path\residents_information2.doc"

This Opens my Word Merge Template, I then have to click on the Merge Button in the Word Template to generate my merged document.

After I print my merged document and close Word I am then left with the Query1 still open on the screen which I then have to close.


My Question is, how can I automate this so the it all happens without any other intervention form the user.

Any ideas or advice.

Kind Regards, keep safe and well.


Dereck
 
This may be an option. If the document residents_information2.doc never changes, make this document an Access report and just run as a report based on Query1.
 
Hi and Thanks for your reply;

I am currently using the code below which goes half way to what I am trying to do. It executes the query and stops at the Word Merge Template. Any ideas how I can ajust the code to automate the actual merge and print of the end result:

CODE:

Private Sub merge_Click()
On Error GoTo Err_merge_Click
'Developed by Robert Sang for Connect Learning Centres 2003

'Load the mail merge document as an object
Dim objWord As Object
Set objWord = GetObject("F:\Ley_Community\Referrals\Referral2\Residents_Information2.doc", "Word.Document")
'Make Word visible
objWord.Application.Visible = True

'Open the mail merge data source (this database and record)
objWord.MailMerge.OpenDataSource _
Name:="F:\Ley_Community\Referrals\Referral2\Referral.mdb", _
LinkToSource:=True, _
Connection:="QUERY AdmissionsQuery", _
SQLStatement:="SELECT * FROM [ReferralsMainAdmissionForm] WHERE [Referral Reference] = " & Referral_Reference
'Execute the mail merge
objWord.MailMerge.Execute


Exit_merge_Click:
Exit Sub

Err_merge_Click:
MsgBox Err.Description
Resume Exit_merge_Click

End Sub


Kind Regards, keep safe and well

Dereck
 
Navyguy said:
Try this. I use this to print several different documents from different buttons based on a query.

I press the button, merges the documents and prints and closes all in the background. You don't even know you are printing a word document. I got lots of help from the forum on this.

http://www.access-programmers.co.uk/forums/showthread.php?t=62159

Navyguy

Hi and thanks for your reply.

I have tried to use your Function but I get an error:

Function MergeIt()
Dim objWord As Word.Document ***Error Here***

"user defined type not defined"

Any ideas

Kind Regards


Dereck
 

Users who are viewing this thread

Back
Top Bottom