Almost completed the merge

Steven811

Registered User.
Local time
Today, 19:48
Joined
Apr 18, 2004
Messages
133
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
 
Steven,

may be, it's the "Me"-Reference?
When evaluating the 1stsubFormField, "Me" references the parent form correctly. But after that evaluation, it references the 1stsubform, so the evaluation of Your 2ndsubFormField will fail.... but I'm not really sure :cool:

Try to reference without "Me"...

Hope that will be a solution.

Agnostiker
 

Users who are viewing this thread

Back
Top Bottom