I have the following code for mail merge..It seems to be working, but even though I have the sql in the sql statement, it is still popping up a few things, which I need to avoid..
The first one is Microsoft Word Document with Yes/No buttons:
Opening this document will run the following SQL Command:
Select * from '00005067'
Data from your database will be placed in the document. Do you want to continue?
The next one is a window with a list of tables from the database to select from, even though I am already defining the sql statement in the code below..
Is it possible to avoid these two prompts?
Any help from you will be greatly appreciated. Thank you for your help in advance.
Code: ( text )
Function MergeIt(fsHistoryId As String, fsTemplateId As String)
Dim objWord As Word.Document
Dim lsSql As String
lsSql = "Select * from " & [fsTemplateId] & " where historyId = " & fsHistoryId
Set objWord = GetObject("H:\RDA\ITS\MailMerge\" & fsTemplateId & ".doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:= CurrentDb.name, _
LinkToSource:=True, _
Connection:="TABLE " & [fsTemplateId], _
SQLStatement:=lsSql
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
The first one is Microsoft Word Document with Yes/No buttons:
Opening this document will run the following SQL Command:
Select * from '00005067'
Data from your database will be placed in the document. Do you want to continue?
The next one is a window with a list of tables from the database to select from, even though I am already defining the sql statement in the code below..
Is it possible to avoid these two prompts?
Any help from you will be greatly appreciated. Thank you for your help in advance.
Code: ( text )
Function MergeIt(fsHistoryId As String, fsTemplateId As String)
Dim objWord As Word.Document
Dim lsSql As String
lsSql = "Select * from " & [fsTemplateId] & " where historyId = " & fsHistoryId
Set objWord = GetObject("H:\RDA\ITS\MailMerge\" & fsTemplateId & ".doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:= CurrentDb.name, _
LinkToSource:=True, _
Connection:="TABLE " & [fsTemplateId], _
SQLStatement:=lsSql
' Execute the mail merge.
objWord.MailMerge.Execute
End Function