I am trying to merge multiple records into one Word document with the following code, however only the first record is merged into the single document....What do I need to add to my code below.
Many thanks
Sub ConstructStudentReport()
Dim objWRD As Word.Application
Dim objDoc As Word.Document
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryIndividualStudentReport4"
DoCmd.SetWarnings True
Set objWRD = CreateObject("Word.Application")
objWRD.Visible = True
Set objDoc = objWRD.Documents.Add("c:\accessdocs\School Report4.dot", , , True)
objWRD.ScreenUpdating = False
objWRD.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
If DLookup("sex", "tblIndividualStudentReport4") = "Male" Then
objDoc.Bookmarks("bmkShe").Select
objWRD.Selection.Delete
End If
If DLookup("sex", "tblIndividualStudentReport4") = "Male" Then
objDoc.Bookmarks("bmkHer").Select
objWRD.Selection.Delete
End If
'''''''''''''''''''''''Now the more complicated
''''''''''''''''''''''''To find all instances of his and her delete them
objWRD.Visible = True
objWRD.ActiveDocument.MailMerge.Execute '<*******
objWRD.ScreenUpdating = True
DoCmd.Close
objWRD.ActiveDocument.Saved = True
objDoc.Close False '<************************
Set objDoc = Nothing
Set objWRD = Nothing
End Sub
Many thanks
Sub ConstructStudentReport()
Dim objWRD As Word.Application
Dim objDoc As Word.Document
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryIndividualStudentReport4"
DoCmd.SetWarnings True
Set objWRD = CreateObject("Word.Application")
objWRD.Visible = True
Set objDoc = objWRD.Documents.Add("c:\accessdocs\School Report4.dot", , , True)
objWRD.ScreenUpdating = False
objWRD.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
If DLookup("sex", "tblIndividualStudentReport4") = "Male" Then
objDoc.Bookmarks("bmkShe").Select
objWRD.Selection.Delete
End If
If DLookup("sex", "tblIndividualStudentReport4") = "Male" Then
objDoc.Bookmarks("bmkHer").Select
objWRD.Selection.Delete
End If
'''''''''''''''''''''''Now the more complicated
''''''''''''''''''''''''To find all instances of his and her delete them
objWRD.Visible = True
objWRD.ActiveDocument.MailMerge.Execute '<*******
objWRD.ScreenUpdating = True
DoCmd.Close
objWRD.ActiveDocument.Saved = True
objDoc.Close False '<************************
Set objDoc = Nothing
Set objWRD = Nothing
End Sub