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