PDA

View Full Version : Help W Access 2010 Mail Merge to Word



zbud
03-10-2019, 03:10 PM
can't seem to get this code to work, any thoughts appreciated
Bud

Function MergeIt(strWordFile As String, Optional lngEvent As Long, Optional alternate As Long) As Boolean
Dim objWord As Word.Document
Dim strFileLocation As String, mysql As String
Dim myDB As Database, rst As DAO.Recordset, RecNumber As Long
Dim strConnect As String, strSql As String



MergeIt = False
Set myDB = CurrentDb()
mysql = "Select * from zstblBackEnds"
Set rst = myDB.OpenRecordset(mysql, dbOpenSnapshot)

strFileLocation = rst("Path") & "" & strWordFile 'file location


strConnect = "Table tmpDonors-Generic" 'connection
strSql = "select * from [tmpDonors-Generic]"



Set objWord = GetObject(strFileLocation, "Word.Document")


objWord.Application.Visible = False

' Set the mail merge data source as the OLF Front End database.

With objWord.MailMerge
.OpenDataSource _
Name:="C:\my Documents\OurLady2003.mdb", _
AddToRecentFiles:=False, _
LinkToSource:=True, _
Connection:=strConnect, _
SQLStatement:=strSql

.Destination = wdSendToNewDocument
.Execute Pause:=False
End With

' Execute the mail merge.

objWord.MailMerge.Execute

End If
rst.Close
Set rst = Nothing
Set myDB = Nothing
End Function

macropod
03-10-2019, 07:30 PM
Your "Connection:=strConnect", populated as it is via "strConnect = "Table tmpDonors-Generic" 'connection" is incomplete. For an idea of what's required, see Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks thread at:
http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html