0

I currently have a Microsoft Access Database (file format is 2007-2016) that we use to track open orders and print all the required documents. I have created a word document that pulls information from this database using MailMerge. This document works flawlessly by itself. Meaning that if I actually double click the document it opens correctly asking me if I want to pull the information from the database. The issue is that if I open it via a command button in the database I the document opens but I will not get the MailMerge dialog asking if I want to pull the information.

Here is the code I am using at the moment to open the document.

Private Sub Print_Click()

If IsNull(Me.DateShipped.Value) Then
    Me.DateShipped = Date
End If
DoCmd.RunCommand acCmdSaveRecord
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("F:\Database\merge\INDIVIDUAL.docx")
Set wrdApp = Nothing
Set wrdDoc = Nothing
DoCmd.RunCommand acCmdSaveRecord

Any help will be appreciated.

Thank you

Joel

  • Does the merge actually happen? – June7 Feb 12 '22 at 19:29
  • Does this answer your question? [Mail merge started by VBA in Access let Word open Database again](https://stackoverflow.com/questions/3905580/mail-merge-started-by-vba-in-access-let-word-open-database-again) – June7 Feb 12 '22 at 19:29
  • The merge seems to happen, however, I only see one record, and that record is not the correct record that should have been merged. – Joel Driver Feb 14 '22 at 05:06
  • Review this tutorial https://www.tek-tips.com/faqs.cfm?fid=3237. Code works for me. If want to limit merge to specific record(s), use WHERE clause in the SQLStatement for OpenDataSource method. I used a table as source, and did not utilize SetQuery procedure, just Sub OpenMergedDoc. However, if I try running code twice in a row, get error - have to close db to clear it. – June7 Feb 14 '22 at 13:04

0 Answers0