E
Evahn Derkley
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
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