I get this message box when I automate a mail merge through access vba. How do I make this dialogue disappear?
Here is my code:
Code:
Public Function MailMergeLetters() Dim pathMergeTemplate As String
'Get the word template from the Letters folder
pathMergeTemplate = "C:\Cole Directory\Letters\"
DoCmd.OutputTo acOutputQuery, "Letters", acFormatExcel, "C:\Cole Directory\Letters\Letters.xls", False
Dim appWord As Object
Dim docWordLetter As Object
Dim docWordEnvelope As Object
Set appWord = CreateObject("Word.Application")
appWord.Application.visible = True
' Open the template in the Letters folder:
Set docWordLetter = appWord.Documents.Add(Template:=pathMergeTemplate & "CMA.dot")
Set docWordEnvelope = appWord.Documents.Add(Template:=pathMergeTemplate & "Envelope.dot")
'Now I can mail merge without involving currentproject of my Access app
docWordLetter.MailMerge.OpenDataSource Name:=pathMergeTemplate & "Letters.xls", LinkToSource:=False
docWordLetter.MailMerge.Execute
docWordEnvelope.MailMerge.OpenDataSource Name:=pathMergeTemplate & "Letters.xls", LinkToSource:=False
docWordEnvelope.MailMerge.Execute
docWordLetter.Close wdDoNotSaveChanges
docWordEnvelope.Close wdDoNotSaveChanges
Set docWordLetter = Nothing
Set docWordEnvelope = Nothing
Set appWord = Nothing
'------------------------------------------------------------------------------
'End Code Block:
'------------------------------------------------------------------------------
Finally:
Exit Function
Hell:
MsgBox Err.Description & " " & Err.Number, vbExclamation, APPHELP
On Error Resume Next
Set docWordLetter = Nothing
Set docWordEnvelope = Nothing
Set appWord = Nothing
Resume Finally
End Function