Mail Merge Code Problem

  • Thread starter Dazed And Confused
  • Start date
D

Dazed And Confused

I am new (I know next to nothing) to mail merges, but want to merge
data in an Access select query with a word document. After much
searching and copying and pasting and generally messing around, I
finally came up with the following code which I run from the Access VB
Editor:

Function MergeLeaveSlips()
Dim objWord As Word.Document
Set objWord = GetObject("C:\Work\LeaveSlipsMerge_Test.doc",
"Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\Work\LeaveSlipsMergeDB_Test.mdb", _
LinkToSource:=True, _
Connection:="Query Leave_Slips_Test", _
SQLStatement:="SELECT * FROM [Leave_Slips_Test]"
objWord.MailMerge.Execute
End Function

What happens is I get a message telling me that "This document will
run the following command: Select * From Leave_Slips_Test . . ."
If I click okay, it then brings up a screen to select the data source.
I need to find a way that the "This document . . ." message won't show
up and it won't ask the user for a data source. Bearing in mind that
I barely understand what this code even does, can anyone help before I
lose what little hair I have?
Thanks very much!!!
SJ
 
M

M.

Take a look at the following knowledge base article about the warning and how
to prevent it (registry edit required)

Good luck,

M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top