Almost- but not quite
I have been testing using your suggestion and with some minor change to your suggested code. However something else is wrong or the placement of the code is wrong. I paste the code underneath (but have deleted the majority of the code you do not need to see in the middle). You can see the places I have tried your suggested code
Sub ConstructVenStatement(Optional IsEmail As Boolean)
Dim objWRD As Word.Application
Dim objDoc As Word.Document
Dim stDocName As String
stDocName = "frmStatementIsComing"
Dim X As Integer
Dim SaveDoc As Boolean
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryStatementVen"
DoCmd.SetWarnings True
DoCmd.OpenForm stDocName
Set objWRD = CreateObject("Word.Application")
'objWRD.ActiveWindow.View = wdPrintView
objWRD.Visible = False
'objWRD.ActiveWindow.View = wdPrintView
'Then I have tried to put it in just before the document is saved see below
If IsEmail Then
Set objDoc = objWRD.Documents.Add(AccessDocsPath & "\Vendor Statements Email.dot", , , True)
Else
Set objDoc = objWRD.Documents.Add(AccessDocsPath & "\Vendor Statements.dot", , , True)
End If
objWRD.ScreenUpdating = False
objWRD.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
'''''''''' SEVERAL PAGES OF CODE IN HERE
objWRD.Visible = True
objWRD.ActiveDocument.MailMerge.Execute
objWRD.ActiveWindow.View = wdPrintView
objWRD.ScreenUpdating = True
DoCmd.Close
objWRD.ActiveDocument.Saved = True
SaveDoc = False
SaveDoc = IsEmail
If SaveDoc = True Then
objDoc.MailMerge.DataSource.QueryString = ""
objDoc.SaveAs CurrentProject.Path & "\VenStatEmail.Doc", , , , , , True
objDoc.Close False
Else
objDoc.Close False '<************************
End If
Set objDoc = Nothing
Set objWRD = Nothing
End Sub
Have you got any ideas of where that code should be positioned?