Hi
I have set up a mail merge via a cmd button so that the current form recordset is transfered to book marked fields in Word, field by field.
The problem is that once I get to the 3rd form (2nd sub form) Access does not complete the transfer, no error message. I know that this code works as I have used it via a cmd button with the subForm as the parent.
The bookmarks remain in the word document for the unmerged fields.
When I then use the cmd button on the parent, the transfer works successfully through the parent and the 1st subForm and stops there. The code that I am using is as follows:
Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("C:\MyFile.doc")
'ParentForm
.ActiveDocument.Bookmarks("ParentField").Select
.Selection.Text = (CStr(Forms!ParentForm!ParentField))
'1st SubForm
.ActiveDocument.Bookmarks("1stsubFormField").Select
.Selection.Text = (CStr(Me!1stSubForm.Form!1stsubFormField))
'2nd subForm
.ActiveDocument.Bookmarks("2ndsubFormField").Select
.Selection.Text = (CStr(Me!2ndsubForm.Form!2ndsubFormField))
MergeButton_Err:
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub
I'd be really grateful for any advice.
Steven811
I have set up a mail merge via a cmd button so that the current form recordset is transfered to book marked fields in Word, field by field.
The problem is that once I get to the 3rd form (2nd sub form) Access does not complete the transfer, no error message. I know that this code works as I have used it via a cmd button with the subForm as the parent.
The bookmarks remain in the word document for the unmerged fields.
When I then use the cmd button on the parent, the transfer works successfully through the parent and the 1st subForm and stops there. The code that I am using is as follows:
Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("C:\MyFile.doc")
'ParentForm
.ActiveDocument.Bookmarks("ParentField").Select
.Selection.Text = (CStr(Forms!ParentForm!ParentField))
'1st SubForm
.ActiveDocument.Bookmarks("1stsubFormField").Select
.Selection.Text = (CStr(Me!1stSubForm.Form!1stsubFormField))
'2nd subForm
.ActiveDocument.Bookmarks("2ndsubFormField").Select
.Selection.Text = (CStr(Me!2ndsubForm.Form!2ndsubFormField))
MergeButton_Err:
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub
I'd be really grateful for any advice.
Steven811