0

Mail merge from Access 2013, not Access 2000

There are docs for mail merge with old versions of access: https://support.microsoft.com/en-us/kb/209976

But I am unable to find any docs or advice for 2013 versions.

Aim: have a button in MS Access that triggers a mail merge based on selected data.

Problem:
While the mail merge works fine if I do it by hand, and export my data before doing the merge. It fails if I try to create a live link. My tables are Office 365 style share point lists - this looks to be causing time out problems and locking problems. So I suspect maybe I need to do an export before I can do the merge.

Access 2000 style mail merge code:

Function MergeIt()
   Dim objWord As Word.Document
   Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
   ' Make Word visible.
   objWord.Application.Visible = True
   ' Set the mail merge data source as the Northwind database.
   objWord.MailMerge.OpenDataSource _
      Name:="C:\Program Files\Microsoft " & _
    "Office\Office\Samples\Northwind.mdb", _
      LinkToSource:=True, _
      Connection:="TABLE Customers", _
      SQLStatement:="SELECT * FROM [Customers]"
   ' Execute the mail merge.
   objWord.MailMerge.Execute
End Function
eddyparkinson
  • 3,680
  • 4
  • 26
  • 52

1 Answers1

0

Export as xls then run the mail merge.

Private Sub Command53_Click()

   DoCmd.OutputTo acOutputQuery, "Mail Merge Query Name", acFormatXLS, "Temp export mail merge file.xls"

   Set objWord = GetObject("path to Mail Merge file.docx", "Word.Document")
   ' objWord.Application.Visible = True

   objWord.MailMerge.OpenDataSource _
      Name:="Temp export mail merge file.xls", _
      ReadOnly:=True, _
      SQLStatement:="SELECT * FROM [Mail Merge Query Name$]"
   objWord.MailMerge.Execute
   objWord.Application.ActiveDocument.SaveAs2 FileName:="TmpMergeOuput.docx"
   objWord.Application.ActiveDocument.Close
   objWord.Close SaveChanges:=wdDoNotSaveChanges
End Sub

Notes:

Community
  • 1
  • 1
eddyparkinson
  • 3,680
  • 4
  • 26
  • 52