add names from database into a form letter using word

D

Daniel

how can I add names in a form letter in word from the names contained in my
database of names?
 
P

PC Datasheet

First, go to Word Help file and look up how to create and use templates.
Then see below my signature line.


--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
[email protected]
www.pcdatasheet.com

If you don't get the help you need in the newsgroup, I can help you for a
very reasonable fee.
Over 1000 Access users have come to me for help.
Remember that a lone man built the Ark. A large group of professionals built
the Titanic.

From my file ---------
Creating a form letter with data from Access



1.. Create a Word template for the form letter. In the template use the
Insert -
Bookmark command to create a bookmark at each location in the text where
you'll want to insert Access data.
Example: the Word template name is C:\FormLetter.dot. For this example,
I'm using simple Name and Address fields, so you should create a bookmark
named FirstName and another named LastName.

2.. In Access, open any Module in design view. Then select Tools \
References
and make sure that you have a reference to the appropriate Word library.
Look for "Microsoft Word xx.x Object Library, where xx.x is the version
number. For this example, you will also need a reference to DAO.

3.. Behind a command button on a form, insert the following code.

Dim objWord As Object
' Open Microsoft Word using automation
Set objWord = New Word.Application
objWord.Documents.Add "c:\FormLetter.dot"
objWord.Visible = True

If objWord.ActiveDocument.Bookmarks.Exists("FirstName") = True Then
objWord.ActiveDocument.Bookmarks("FirstName").Range.Text = me!FirstName
End If

If objWord.ActiveDocument.Bookmarks.Exists("LastName") = True Then
objWord.ActiveDocument.Bookmarks("LastName").Range.Text = me!LastName
End If

' ... continue reading data from form and inserting into bookmark


Note: In addition, you can also create multiple documents in Word while
looping through a recordset in Access.
 
V

Vincent Johns

PC said:
First, go to Word Help file and look up how to create and use templates.
...

More helpful than "templates", if I understand the question correctly,
would be "Mail Merge". You link that to your database of names, and
plug the names (and other desired fields) into your form letter.

You might choose to save it as a template, for future use, or you might
just save it as a document and modify it as needed in the future.
 
Top