By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Mail Merge from Access

P: 9
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.

Expand|Select|Wrap|Line Numbers
  1. Function MergeIt(fsHistoryId As String, fsTemplateId As String)
  2.    Dim objWord As Word.Document
  3.    Dim lsSql As String
  4.    lsSql = "Select * from " & [fsTemplateId] & " where historyId = " & fsHistoryId
  5.  
  6.    Set objWord = GetObject("H:\RDA\ITS\MailMerge\" & fsTemplateId & ".doc", "Word.Document")
  7.    ' Make Word visible.
  8.    objWord.Application.Visible = True
  9.    ' Set the mail merge data source as the Northwind database.
  10.    objWord.MailMerge.OpenDataSource _
  11.       Name:= CurrentDb.name, _
  12.       LinkToSource:=True, _
  13.       Connection:="TABLE " & [fsTemplateId], _
  14.       SQLStatement:=lsSql
  15.  
  16.  
  17.    ' Execute the mail merge.
  18.    objWord.MailMerge.Execute
  19. End Function
  20.  
  21.  
  22.  
Jan 11 '08 #1
Share this Question
Share on Google+
5 Replies


P: 45
Did you try:

ObjWord.Application.DisplayAlerts = wdAlertsNone
Jan 11 '08 #2

P: 9
I have tried that and it still doesnt seem to work..I even tried this..

DoCmd.SetWarnings False

It still doesnt work...
Jan 11 '08 #3

P: 45
The Docmd would only set the warnings on the Access app. The warning you are seeing are from the Word app. That's why I included the ObjWord before the command.

Have your included the Word Reference in your Access code page? I think it may help to figure out what commands Word will respond to stop the warnings.
Jan 11 '08 #4

P: 9
I noticed that it is triggering that message box right after executing this command...
Set objWord = GetObject("H:\RDA\ITS\MailMerge\" & fsTemplateId & ".doc", "Word.Document")

objWord.Application.DisplayAlerts = wdAlertsNone is after this line and hence ignoring that...
Jan 11 '08 #5

P: 9
The Docmd would only set the warnings on the Access app. The warning you are seeing are from the Word app. That's why I included the ObjWord before the command.

Have your included the Word Reference in your Access code page? I think it may help to figure out what commands Word will respond to stop the warnings.
by the way, I am referencing the Microsoft word 11.0 object library
Jan 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.