Using a report as a form letter

G

Guest

I have a large database that requires a mail merge into Word for some form letters. This is a pain, I keep having to reset up the Merge Macro. I am not sure why, but it works sometimes and then not other times

So I have been trying to create my letter as a report, and in that letter set the merge fields. However, some of these fields are in the body of the letter. I have tried to paste the letter in an actual text type box, this works, but I cannot insert another text box in the middle of it for the data that needs to be inserted.

Has anybody done this? Any helpful hints on how to do it?
 
C

Cheryl Fischer

Cindy,

There are a couple of ways to go about getting your Access data into a Word
document. My preference is to use OLE automation to control Word and fill
bookmarks in a template (.DOT file). Some code that you can play with to
familiarize yourself with the concepts is found below.

First, create a Word template for your form letter. For this example, the
document name is C:\FormLetter.dot. In this template, you'll use the Insert
| Bookmark command to create a bookmark at each location in the text where
you'll want to insert Access data. For this example, I'm using simple Name
and Address fields, although Word Bookmarks can be inserted just about
anywhere..

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 Word version
number. For this example, you will also need a reference to DAO.

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

BEGIN CODE SAMPLE:

Dim objWord As Object

' Open Microsoft Word using automation
Set objWord = New Word.Application

objWord.Documents.Add "c:\FormLetter.dot"
objWord.Visible = True

' The following code is generated from your Access form while it is
' manipulating an instance of Word.
' So, while it looks somewhat like VBA, it's really Word VBA.

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

END CODE SAMPLE

hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Cindy K said:
I have a large database that requires a mail merge into Word for some form
letters. This is a pain, I keep having to reset up the Merge Macro. I am
not sure why, but it works sometimes and then not other times.
So I have been trying to create my letter as a report, and in that letter
set the merge fields. However, some of these fields are in the body of the
letter. I have tried to paste the letter in an actual text type box, this
works, but I cannot insert another text box in the middle of it for the data
that needs to be inserted.
 
A

Arvin Meyer

Cindy K said:
I have a large database that requires a mail merge into Word for some form
letters. This is a pain, I keep having to reset up the Merge Macro. I am
not sure why, but it works sometimes and then not other times.
So I have been trying to create my letter as a report, and in that letter
set the merge fields. However, some of these fields are in the body of the
letter. I have tried to paste the letter in an actual text type box, this
works, but I cannot insert another text box in the middle of it for the data
that needs to be inserted.
Has anybody done this? Any helpful hints on how to do it?

You can do it either as an expression, or in code. To use an expression,
make a large text box and concatenate your text like:

="Now is the time for all good men to come to the aid of their country. " &
[Forms]![MyForm]![txtFirstName] & " is a good man. So is " &
[Forms]![MyForm]![txtField2] & ". If both men are good, then ..."

You get the idea by now.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top