Sub ControlWord()
Dim objWord As New Word.Application
Dim rsContacts As New ADODB.Recordset
Dim strLtrContent As String
rsContacts.ActiveConnection = CurrentProject.Connection
rsContacts.Open "tblContacts"
objWord.Documents.Add
Do While Not rsContacts.EOF
strLtrContent = rsContacts("FirstName") & " " & rsContacts("LastName")
strLtrContent = strLtrContent & rsContacts("Address") & vbCrLf
strLtrContent = strLtrContent & rsContacts("City") & ", " & rsContacts("Region")
strLtrContent = strLtrContent & " " & rsContacts("PostalCode")
strLtrContent = strLtrContent & "Dear " & rsContacts("FirstName") & " "
strLtrContent = strLtrContent & rsContacts("LastName") & ":"
objWord.Selection.EndOf
objWord.Selection.Text = strLtrContent
objWord.Selection.EndOf
objWord.Selection.InsertBreak
rsContacts.MoveNext
Loop
objWord.Visible = True
objWord.PrintPreview = True
End Sub
|