By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,190 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,190 IT Pros & Developers. It's quick & easy.

To run several Word mail merges from Access

P: n/a
I use MS Office 2003 and would like to run several Word mail merges
from Access.

My code so far is given below.

1. The code does not do what I want. I want to save the new document
with the merge result, not the merge template I start out with. At the
moment it saves the latter.

2. I would like all Word documents to be closed in the end.

3. I would like to run several queries and for each of them do a mail
merge to a new document that is being saved.

Any help with 1-3 would be most welcome.

Regards,

Jan Nordgreen

---

Option Compare Database

'References: Microsoft Word 11 Object Library

Private Sub Command0_Click()

' variables
Dim folder As String
folder = "G:\GIS\school administration\reports\"
Dim template As String
template = "report template.doc"
Dim database As String
database = "create report documents.mdb"
Dim objWord As Word.Document
Set objWord = GetObject(folder & template, "Word.Document")

' Make Word visible.
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:=folder & database, _
LinkToSource:=True, _
Connection:="TABLE Test", _
SQLStatement:="SELECT * FROM [Test]"

' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute

' Save the document
objWord.SaveAs FileName:=folder & "7.doc",
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True,
WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False

' Release the object variable.
objWord.Close
Set objWord = Nothing

End Sub
Nov 11 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
damezumari <ja**********@gmail.comwrote:
>I use MS Office 2003 and would like to run several Word mail merges
from Access.

My code so far is given below.
See Albert Kallal's Super Easy Word Merge - Scroll down a ways
http://www.members.shaw.ca/AlbertKal.../msaccess.html

No code required on your part as his tool as all the code needed.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Nov 11 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.