Here is code that I used. You can change the names to correspond to your fields and tables.
Make sure that you have a form letter already made up in word using a .dot template when using this function.
In your form, make a command button that when clicked would reference this function.
Public Function MergetoWord()
' This method creates a new document in MS Word 97 using Automation.
On Error Resume Next
Dim rsCust As Recordset, iTemp As Integer
Dim WordObj As Word.Application
Set rsCust = DBEngine(0).Databases(0).OpenRecordset("Customers", dbOpenTable)
rsCust.Index = "PrimaryKey"
rsCust.Seek "=", Forms!Orders![CustomerNumber]
If rsCust.NoMatch Then
MsgBox "Invalid customer", vbOKOnly
Exit Function
End If
DoCmd.Hourglass True
Set WordObj = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordObj = CreateObject("Word.Application")
End If
WordObj.Visible = True
WordObj.Documents.Add Template:="D:\office97\Templates\thanks.dot", NewTemplate:=False
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="FullName"
WordObj.Selection.TypeText rsCust![ContactName]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="CompanyName"
WordObj.Selection.TypeText rsCust![CompanyName]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="Address1"
WordObj.Selection.TypeText rsCust![Address1]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="Address2"
If IsNull(rsCust![Address2]) Then
WordObj.Selection.TypeText ""
Else
WordObj.Selection.TypeText rsCust![Address2]
End If
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="City"
WordObj.Selection.TypeText rsCust![City]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="State"
WordObj.Selection.TypeText rsCust![State]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="Zipcode"
WordObj.Selection.TypeText rsCust![Zipcode]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="PhoneNumber"
WordObj.Selection.TypeText rsCust![PhoneNumber]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="NumOrdered"
WordObj.Selection.TypeText Forms!Orders![Quantity]
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="ProductOrdered"
If Forms!Orders![Quantity] > 1 Then
WordObj.Selection.TypeText Forms!Orders![Item] & "s"
Else
WordObj.Selection.TypeText Forms!Orders![Item]
End If
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="FName"
iTemp = InStr(rsCust![ContactName], " ")
If iTemp > 0 Then
WordObj.Selection.TypeText Left$(rsCust![ContactName], iTemp - 1)
End If
WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="LetterName"
WordObj.Selection.TypeText rsCust![ContactName]
DoEvents
WordObj.Activate
WordObj.Selection.MoveUp wdLine, 6
' Set the Word Object to nothing to free resources
Set WordObj = Nothing
DoCmd.Hourglass False
Exit Function
TemplateError:
Set WordObj = Nothing
Exit Function
End Function
Good luck.