Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access mail merge

Status
Not open for further replies.

vveluru

Programmer
Jan 11, 2008
3
0
0
US
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
 
You can turn the warnings off and with this command:
objWord.DisplayAlerts = wdAlertsNone

After the mail merge you can turn the warnings on with the following command:
objWord.DisplayAlerts = wdAlertsAll

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top