merge single record

L

LisaVH

I am trying to put data into an access form based on a table (Name, Address,
etc) then hit a button to print out a letter with that info in it.

eg:
<<address>>
Dear <<name>>,
Thank you for your letter of <<date>>
blah blah blah...

I have found several posts for this, but they are really old and the
websites that are recommended are no longer valid. Can anyone help?

Thanks in advance.
Lisa.
 
T

Tim Ferguson

I am trying to put data into an access form based on a table (Name,
Address, etc) then hit a button to print out a letter with that info
in it.

eg:
<<address>>
Dear <<name>>,
Thank you for your letter of <<date>>
blah blah blah...

(1) do it all in Access -- create a report based on the table with the
merge fields in all the right places etc. Then open the report for
previewing or printing with something like

docmd.openreport "MyFormLetter",,,"PersonID = " & Me.txtPersonID.Value

i.e. use the WhereCondition argument to select just the single record.

(2) Do it in Word: create an automation object and use it to create a new
document based on your template, and poke the data values into bookmarks
embedded in the document. This is air code from memory, so treat it with
a _huge_ amount of caution, but you should get the idea:

' late binding is sometimes more robust
set wapp = new Word.Application

' create a new document based on the template
set doc = wapp.Documents.Add("MyFormLetter.dot")

' poke today's date into the first bookmark
doc.Bookmarks("letterDate").Range.Text = format(date(),"dd/mm/yyyy")

' you have to poke in things like hard line breaks yourself
doc.Bookmarks("toAddress").Range.Text = _
txtAddress1.Value & vbVerticalTab & _
txtAddress2.Value & vbVerticalTab & _
txtAddress3.Value

' you can take more flexible decisions than are available in
' a straight merge
if cboRelation.Value = "Family" then
doc.Bookmarks("Salutation").Range.Text = "Darling "

else
doc.Bookmarks("Salutation").Range.Text = "Dear " & txtFirstName.Value

end if

' etc, then finish off
doc.PrintOut


Hope that helps


Tim F
 
B

Barry Gilbert

The simplest way is to create a report that pulls in the form's values. I'm
guessing, though, that you want to do a Mail Merge with Word. Search MSDN or
the web for
Access "Mail Merge"
and you should get a lot of articles.

Barry
 

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