I am trying to create a simple button on a form which when pressed merges the current record into a Word 2003 document.
I am using the shown below - from the MS Knowledgebase.
Option Compare Database
Private Sub cmdPrintLetter_Click()
MergeIt
End Sub
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\HMDoors\test.doc", "Word.document")
' Make Word visible
objWord.Application.Visible = True
'Set mail merge data source as current database
objWord.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
Connection:="TABLE tblEmployee", _
SQLStatement:="Select * from [tblEmployee]"
'Execute the Mail Merge
objWord.MailMerge.Execute
End Function
It works after fashion but I have two problems.
1.I get a pop-box warning me that "Opening this document will run the following SQL command, SELECT * from [tblEmployee]. Is there any way I can supress this?
2. Two copies of the Word document open the first is the original merge file, the second document is the megred document with the data in it. Is there anyway I can only open the second one with the merged data?
Many Thanks
I am using the shown below - from the MS Knowledgebase.
Option Compare Database
Private Sub cmdPrintLetter_Click()
MergeIt
End Sub
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\HMDoors\test.doc", "Word.document")
' Make Word visible
objWord.Application.Visible = True
'Set mail merge data source as current database
objWord.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
Connection:="TABLE tblEmployee", _
SQLStatement:="Select * from [tblEmployee]"
'Execute the Mail Merge
objWord.MailMerge.Execute
End Function
It works after fashion but I have two problems.
1.I get a pop-box warning me that "Opening this document will run the following SQL command, SELECT * from [tblEmployee]. Is there any way I can supress this?
2. Two copies of the Word document open the first is the original merge file, the second document is the megred document with the data in it. Is there anyway I can only open the second one with the merged data?
Many Thanks