I currently have a print button and Module to run a mail-merge through a query, of the current results on a form.
When this is run, I get 3 documents open, the template, the merged document and another word document saying mail merge errors even though it works fine. At the beginning you also get a pop up box where you have to click options and check system tables. When the code runs, it creates an excel document from the query, for the record which is to be merged. Once this is done, simply double clicking the word document will ask yes or no to whether you want to merge, without all the unnecessary documents and options, as the merge comes from the excel.
I've attempted to modify the code to just create the excel document and then open the word document, however, when VB is opening a word template it opens as object. When this happens it doesn't run the merge.
Is there a way to open a word template through VB where it creates a new document and runs the merge, the same way as if I double clicked the template from the folder?
Code currently used is:
Private Sub Print_Click()
DoCmd.OutputTo acOutputQuery, "RFQ Query", acFormatXLS, "H:\Request for Quotation\Merge.xls"
Dim oApp As Object
Dim oDoc As Object
Dim sTmpltName As String
sTmpltName = "H:\Request for Quotation\Merge.dot"
On Error Resume Next
Set oApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't running so start it
Set oApp = CreateObject("Word.Application")
On Error GoTo 0
oApp.Visible = True
Set oDoc = oApp.Documents.Add(sTmpltName)
Set oDoc = Nothing
Set oApp = Nothing