My mail merge to Word doesn't work properly: Access opens the Word document then adds the first field into the first bookmark fine, but then does nothing with the other bookmarks. What is wrong?
This the code:
Private Sub Command188_Click()
On Error GoTo MergeButton_Err
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("C:\Documents and Settings\P\Desktop\A\Database\Letters\HAC.doc")
'ParentForm
.ActiveDocument.Bookmarks("ContactName").Select
.Selection.Text = (CStr(Forms!A!ContactName))
.ActiveDocument.Bookmarks("Job").Select
.Selection.Text = (CStr(Forms!A![Job Title]))
.ActiveDocument.Bookmarks("Organisation").Select
.Selection.Text = (CStr(Forms!A!Organisation))
'1st SubForm
.ActiveDocument.Bookmarks("ReturnDate").Selec t
.Selection.Text = (CStr(Me!Orders![Return_Date]))
End With
MergeButton_Err:
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub
This the code:
Private Sub Command188_Click()
On Error GoTo MergeButton_Err
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("C:\Documents and Settings\P\Desktop\A\Database\Letters\HAC.doc")
'ParentForm
.ActiveDocument.Bookmarks("ContactName").Select
.Selection.Text = (CStr(Forms!A!ContactName))
.ActiveDocument.Bookmarks("Job").Select
.Selection.Text = (CStr(Forms!A![Job Title]))
.ActiveDocument.Bookmarks("Organisation").Select
.Selection.Text = (CStr(Forms!A!Organisation))
'1st SubForm
.ActiveDocument.Bookmarks("ReturnDate").Selec t
.Selection.Text = (CStr(Me!Orders![Return_Date]))
End With
MergeButton_Err:
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub