The following code is linked to a command button that starts a word document merge:
Private Sub cmdMergeIt_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery “Approval”
DoCmd.SetWarnings True
Dim WordObj As Word.Document
Dim strPathtoYourDocument As String
strPathtoYourDocument = “C:Front_End_TrackingApproval_Letters” & DLookup(“DocumentName”, “Approval_Letters”, “DocumentID = ” & Me.[Vendor Combo Box].Column(1))
Set WordObj = GetObject(strPathtoYourDocument)
WordObj.Application.Visible = True
WordObj.MailMerge.Destination = wdSendToNewDocument
WordObj.MailMerge.Execute
WordObj.Close wdDoNotSaveChanges
Set WordObj = Nothing
End Sub
This works fine, except there are time where the data is incorrect or incomplete, and access throws up an unfriendly error message of “Word could not merge the main document with the data source because the data records were empty or no data records matched your query options.” Access then proceeds to bring up the approval document template, and spits out another error message “Run time error “5631′:…
I’d like to replace the error messages with something a bit more user friendly like “The approval data is incomplete or incorrect” while at the same time, prevent Access from proceeding with the Word merge. I’ve played around with the “on error event” for the form, but I can’t get it to work.
Thanks