View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Merging Access data into a Word document

See response to your latter post.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Access101" wrote in message
...
You guys look like you know what you're talking about - slick tools.
Maybe
you know this one too:

In my Main Merge doc I have:
fname
fname

In the Data doc I have column heading and two names
fname
Bill
Mike

When I merge, Bill, of course, replaces each fname with Bill and looks
like this:
Bill
Bill
What I want, is this:
Bill
Mike

Is this possible?

Any help is appreciated.

" wrote:

The solution depends on what level of automation that you need.

In Word 2003, you can use Tools Letters/Mailings Mail Merge, and
after selecting the Access table in step 3, check only the one
recipient that you want.

You may also try Albert Kallal's "MergeSingleWord".
http://www.members.shaw.ca/AlbertKal.../msaccess.html

I automated the process with Visual Basic code to merge the current
record being displayed on an Access form. The form has fields to find
and identify the desired record, a command button to launch this code,
and a text box bound the data table primary key called OrderID.

This article was used as a foundation:
http://support.microsoft.com/?id=209976
The code requires reference (Tools References) to Word 11 Object
Library; may need to browse for C:\PF\MS Office\Office11\msword.olb

The Word template should not be bound to a data source. Bind it to a
data source only to easily enter the merge fields, then convert it back
to a normal Word document (Word 2000: Mail Merge Helper 1 Restore
to normal Word document. Word 2003: Mail merge toolbar Main document
setup Normal Word document).

You may get errors from Word such as the "Data Link" window or
complaints that Access is locked and needs an admin password. Post
them to this thread.

Here is the code. Any MVPs and pros, feel free to correct. Sorry for
line wrapping; not sure why it does that.


Function OutputDoc()

Dim appWord As Word.Application
Dim objWord As Word.Document

Set appWord = New Word.Application
Set objWord = appWord.Documents.Open("C:\MergeTemplate.doc")

' Make Word visible.
appWord.Visible = True
' Set the mail merge data source as the database. Note the query
parameter.
objWord.MailMerge.OpenDataSource Name:="Database.mdb",
LinkToSource:=True, Connection:="TABLE tblData", SQLStatement:="SELECT
* FROM [tblData] WHERE [Orders.OrderID] = " & Forms!OrderForm!OrderID
' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute

' clean up and close Word, closing windows in reverse order that
they were opened
Set objWord = appWord.Documents("Form Letters1")
objWord.Close wdDoNotSaveChanges
Set objWord = appWord.Documents("Sampling Request Form - merge.doc")
objWord.SaveAs ("C:\Output.doc")
appWord.Quit
Set appWord = Nothing
End Function


Good luck.


Danny wrote:
Is it possible to take the data from Access, and merge it into just one
Word
document? I wish to create a form letter addressed to one person, using
the
data that I have stored in an Access database. However, the only
options I
have discovered so far are to either create a mass-mailing, or to
create a
poorly formatted report in Access, then use the "publish it" function.
This
outputs again a poorly formatted document.

Is it possible for me to design a form letter in Word, and have it pull
the
data for just one letter, rather than 100?