Individual Mail Merge

Haynesey

Registered User.
Local time
Today, 05:36
Joined
Dec 19, 2001
Messages
190
I need a basic understanding of how I send a letter, say an introductory thank you letter, from a current record. I would like to have a command button on the record that would generate a letter automatically. Do I create the letter in Microsoft Word using mail merge ? and if so how do I get it to select just the current record ? and is it possible to show on the individual record that the letter had been sent & on what date? I can already do mail merges by using queries etc but I can't get my head round how to do a one off for the current record

Please help.

Many thanks
Lee
 
I have set up quite large mail merges in word linked to tables in databases.

I have it in the form of a "letter template" and use the query option within word to select the record or records I want.

Ie I have over 1000 contracts and set the field "contractno" to the one i want to pick up and it merges the information for this contract number only.

To be honest I did it along time ago and took some working out particularly with the ODBC connections......but stick with it and you can acheive fantastic results.

From memory use word and connect to the database as opposed to trying to open word etc from access.

Richio
 
Lee:

The trick is to include your underlying table's KEY FIELD in the form from which you are intiating the merge. (On the form, I set that field's Visible property to 'no.') Then... create a query that has the same table's KEY FIELD in it, with the Criteria set to the form's entry of that key field. For example: [forms]![form name]![key field name] as the criteria. That way the query will find the data only currently showing in the form.

Then... create a command button in the form that runs the query, and intitiate the merge. Here is the code that was given to me that works as the OnClick property (Build Event):

=======================

Dim objWord As Word.Document

Set objWord = GetObject("DocumentName", "Word.Document")

' Make Word visible.
objWord.Application.Visible = True

' Set the mail merge data source
objWord.MailMerge.OpenDataSource Name:="DatabaseName", _
LinkToSource:=True, _
Connection:="QUERY QueryName"

objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute

'The following line must follow the Execute statement because the PrintBackground property is available only when a document window is active. Without this line of code, the function will end before Word can print the merged document.

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut

End Sub

=======================

The Word document is a mail merge document and has to have the fields from the merge in it. Go through the mail merge function in Word to set up the document, with the data source set to the database query... then use the 'enter merge field' button to place the fields in the document.

This works every time. If you're working on a network, be sure to put the true path to the document, and not the mapped path.


Hope this helps.

Tom
 
Last edited:

Users who are viewing this thread

Back
Top Bottom