How do I automate mail merge in Access 2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to mail merge a query into a word document, how ever this query is
generated by a user inputting data into a form and I want the user to be able
to click on a button that runs the query and then merges the data into the
existing word document.
 
Buffy:

The following KB article may be a useful reference.

http://support.microsoft.com/default.aspx?scid=kb;en-us;209976

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I want to mail merge a query into a word document, how ever this query is
generated by a user inputting data into a form and I want the user to be
able
to click on a button that runs the query and then merges the data into the
existing word document.
 
Hi Alex

I am trying this out, and have created a document with a couple of Merge
Fields defined within it. However whenever I run the module, I get prompted
for the table (after the merge document is opened) - I thought the
"connection" parameter supplied this - what am I doing wrong?

Function MergeIt()

Dim objWord As Word.Document
Set objWord = GetObject("C:\Documents and Settings\My
documents\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the relevent database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\My Documents\MergeBE.mdb ", _
LinkToSource:=True, _
Connection:="TABLE T_Customer", _
SQLStatement:="SELECT * FROM [T_Customer]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function

Many Thanks


Chris
 
Hi Chris,
can't say you for sure. Perhaps your MergeBE.mdb opened exclusively? BTW,
you have a extra space after MergeBE.mdb - this could be a reason also

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com



Chris said:
Hi Alex

I am trying this out, and have created a document with a couple of Merge
Fields defined within it. However whenever I run the module, I get
prompted
for the table (after the merge document is opened) - I thought the
"connection" parameter supplied this - what am I doing wrong?

Function MergeIt()

Dim objWord As Word.Document
Set objWord = GetObject("C:\Documents and Settings\My
documents\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the relevent database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\My Documents\MergeBE.mdb ", _
LinkToSource:=True, _
Connection:="TABLE T_Customer", _
SQLStatement:="SELECT * FROM [T_Customer]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function

Many Thanks


Chris


Alex Dybenko said:
 
I am having a similar problem. This is my revised code:

Function MergeIt()
Dim objWord As Word.Document
' Set objWord = GetObject("G:\Highway Travel Permit\Highway Permit
Demo\MergeLetter", "Word.Document")
Set objWord = GetObject("MergeLetter", "Word.Document")

' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="Highway Travel.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblCustomerProfile", _
SQLStatement:="SELECT * FROM tblCustomerProfile"

' Execute the mail merge.
objWord.MailMerge.Execute
End Function

My error message is" File name or class name not found during Automation
operation.

I also added Word 10 Object Library to the reference list.

What I am doing wrong.?

Alex Dybenko said:
Hi Chris,
can't say you for sure. Perhaps your MergeBE.mdb opened exclusively? BTW,
you have a extra space after MergeBE.mdb - this could be a reason also

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com



Chris said:
Hi Alex

I am trying this out, and have created a document with a couple of Merge
Fields defined within it. However whenever I run the module, I get
prompted
for the table (after the merge document is opened) - I thought the
"connection" parameter supplied this - what am I doing wrong?

Function MergeIt()

Dim objWord As Word.Document
Set objWord = GetObject("C:\Documents and Settings\My
documents\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the relevent database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\My Documents\MergeBE.mdb ", _
LinkToSource:=True, _
Connection:="TABLE T_Customer", _
SQLStatement:="SELECT * FROM [T_Customer]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function

Many Thanks


Chris


Alex Dybenko said:
Hi,
try to look here:
http://www.mvps.org/access/general/gen0010.htm
--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com


I want to mail merge a query into a word document, how ever this query
is
generated by a user inputting data into a form and I want the user to
be
able
to click on a button that runs the query and then merges the data into
the
existing word document.
 
Back
Top