PC Review


Reply
Thread Tools Rate Thread

Controlling Word mailmerge from Access VBA

 
 
Evahn Derkley
Guest
Posts: n/a
 
      17th Sep 2003
Hi

I'm having a problem with setting up a Word 2000 mailmerge
document to use an Access query for the data source and
running this all from an Access 2000 VBA module.

What happens is that the VBA code opens the Word template
document and when it runs the MailMerge.OpenDataSource
method, Word opens a second copy of the database passed
using the "Name" parameter and tries to use this as it's
data source instead of the already open database.

This does work if the mailmerge data source is to be a
Table, however it does open a new copy of the database
everytime the statement is run.

If a query is passed as the mailmerge data source and the
query has references to fields on an open form, the
mailmerge then fails with numerous errors. This seems to
be because the query is looking for fields on a form on
the newly opened copy of the database and doesn't find
them.

How can I stop Word from opening this second copy of the
database and use the running copy instead?

The Access database does not have any security on it and
I'm using Microsoft Office 2000 with SR-1 and SP-2
installed. It does the same behaviour on workstations
with Access 2000 Run-time installed.


Tidied up code from Access VBA module:

Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim strSQL As String

Set WordObj = CreateObject("Word.Application")
WordObj.Visible = True
Set WordDoc = .Documents.Open(FileName:="c:\template.doc",
ReadOnly:=True)
strSQL = "Select * from [qMailMergeSource]"
WordDoc.MailMerge.OpenDataSource Name:=CurrentDb.Name,
LinkToSource:=True, Revert:=True, Connection:="QUERY
qMailMergeSource", SQLStatement:=strSQL
WordDoc.MailMerge.Destination = wdSendToNewDocument
WordDoc.MailMerge.Execute


NB: I've tried opening the Word document as non-Readonly
and I've also tried different combinations of the
LinkToSource and Revert fields.


Thanks
Evahn

 
Reply With Quote
 
 
 
 
Albert D. Kallal
Guest
Posts: n/a
 
      17th Sep 2003
The launching of the 2nd copy is a know bug. There is a workaround at

http://www.mvps.org/access/bugs/bugs0011.htm

However , I a have a battle tested and ready to go word merge example that
eliminates the above bug, and MANY other problems. I suggest you download my
example, and give it a try.

It is designed to word template enable any *existing* form you have with ONE
line of code. Give it a try, and read the notes on how I made the merge
reliable.

Check out:

http://www.attcanada.net/~kallal.msn.../msaccess.html


--
Albert D. Kallal (MVP)
Edmonton, Alberta Canada
(E-Mail Removed)
http://www.attcanada.net/~kallal.msn


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mailmerge from Access to Word Jan Microsoft Access 16 3rd Sep 2009 12:28 AM
Access/Word 2003 Report OR Word mailmerge steward Microsoft Access 3 10th Jul 2008 12:34 AM
mailmerge to Word From Access =?Utf-8?B?TG9yYWxlZQ==?= Microsoft Access VBA Modules 13 29th Nov 2006 04:36 AM
MailMerge from Access to Word =?Utf-8?B?TGFuYQ==?= Microsoft Access Form Coding 0 5th Sep 2006 03:34 PM
Word MailMerge from Access Ed Warren Microsoft Access Getting Started 6 1st Jul 2004 02:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:05 AM.