I am using the Jet connection. I eventually got it to
work by copying the db, deleting all but the mail merge
table and then exporting all other tables to the new db.
Not sure why it works, but when I started from a fresh db
it just wouldn't work. Perhaps the Word to Access
interface uses some sort of table numbering control
rather than table name. This may be an oversimplified
perception. Here is the code (by the way, it had the
same problem when I did it manually in Word):
With gobjWord
' Make Word visible
.Visible = True
' Open the word document
.Documents.Open "Z:\TheBackEndDB\MailMergeDocuments\"
& strMailMergeLetterName
' Give the document time to open
DoEvents
' Use the MailMerge method to perform a mail merge
With gobjWord.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute
End With
' Send the result to the print preview window
.ActiveDocument.PrintPreview 'Preview
' Make Word visible
.Visible = True
End With
Really appreciate your insight.
Winston
First, from your description I'd suspect that you secured the tables in some
way when you first did this and that the security information is being
carried across if you copy but not if you create tables from scratch.
As for specific points...
> I am using the Jet connection.
OK, not sure what you mean by this - did it involve creating a .odc file? I
was thinking of "DDE", "ODBC", "OLEDB" connection types.
> Perhaps the Word to Access
> interface uses some sort of table numbering control
> rather than table name.
Nothing I've ever seen would lead me to this hypothesis - as far as I know
it just uses a combination of the following:
a. the database (.mdb) file name
b. a connection string, whose contents vary depending on the type of
connection
c. an SQL query
(b) and (c) may be embedded in Word or specified inside a .odc.
You may be able to see what Word is using for (b) and (c) are by printing
the values of
gobjWord.ActiveDocument.MailMerge.DataSource.ConnectString
and
gobjWord.ActiveDocument.MailMerge.DataSource.QueryString
The code you provide doesn't have an OpenDataSource call in it so the
database connection must have been specified beforehand in Word. FWIW as a
matter of sound programming practice I would probably use something more
like
Set objDoc = .Documents.Open("Z:\TheBackEndDB\MailMergeDocuments\" &
strMailMergeLetterName)
then
With objDoc.MailMerge
etc.
--
Peter Jamieson - Word MVP
> I am using the Jet connection. I eventually got it to
> work by copying the db, deleting all but the mail merge
[quoted text clipped - 92 lines]
> >
> >.
Winston Abernathy - 24 Nov 2003 21:20 GMT
Thanks... I will have to do a bit of work to check out
your suggestions. They sound quite probable.
Thanks again.
Winston Abernathy
>-----Original Message-----
>First, from your description I'd suspect that you secured the tables in some
[quoted text clipped - 13 lines]
>
>Nothing I've ever seen would lead me to this hypothesis -
as far as I know
>it just uses a combination of the following:
> a. the database (.mdb) file name
[quoted text clipped - 127 lines]
>
>.