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
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