View Single Post
  #1  
Old August 4th, 2004, 11:14 AM
Anthony
external usenet poster
 
Posts: n/a
Default Mail merge to Word from Access 2000

Hi

I am trying to create code for a command button on a MS
Access 2000 form,
which, when clicked, uses mail merge to create a Word
document for the
active record only.

The code I am using (see below) is contained within a
Module in Access. It
successfully creates merges Word docs for ALL of the
records, but I want to
create a single document for the active record only.

*****************start code*********************
Function MergeIt()

Dim objWord As Word.Document
Set objWord = GetObject("C:\My
Doc.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind
database.
objWord.MailMerge.OpenDataSource _
Name:="C:\My Database File.mdb", _
LinkToSource:=True, _
Connection:="QUERY Patient Details Query", _
SQLStatement:="SELECT * FROM [Patient Details Query]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function

****************end code************************

I tried inserting a WHERE statement within the
SQLStatement

ie. SQLStatement:="SELECT * FROM [Patient Details Query]"
& _
"WHERE [PatientID]= Me!PatientID"

but this didn't work.

Any ideas for a WHERE statement that will merge only a
single record into
Word? If not, is there perhaps another approach?

Thanks in Advance
Anthony