View Single Post
  #16   Report Post  
Murray Muspratt-Rouse Murray Muspratt-Rouse is offline
Member
 
Location: Mill Hill, London, England
Posts: 44
Default

Hi Peter!

So you are giving me another learning opportunity - Javascript. I'm afraid I do not follow what you say about naming the table on the odc:CommandTextmytable/odc:CommandText line. I was wondering where the SQL statement would go in. Is this the place?

As I have told you in another reply post I have solved the problem of linking Word documents to the data source by exporting the table that is loaded with the mail merge data as a spreadsheet and using that to insert the merge fields. When the VBA code executes Word inserts data from the Access table - it obviously has the same name!

Thank you again for all your help

Murray

[quote=Peter Jamieson;394960]If you try to connect /manually/ with an empty .odc file, Word cannot
connect because it expects all the necessary information to be in the
..odc and it (probably) will not ask to find out the rest of the information.

In other words, the empty .odc can only be used if you are connecting
from VBA and providing the necessary info. in there.

When I'm testing this kind of stuff I generally have a test VBA
subroutine that just contains

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

followed by the OpenDataSource call. This is simply because for some
connection types, the connection cannot succeed unless you have closed
any existing connection.

If you want to try using a "real" .odc, here's a sample taken from a
Word 2003 system (Word 2007 uses a slightly different .odc XML format
that has, finally, been documented, but will probably work with the
older ones. I am assuming you are doing a connection to
a database called c:\a\mydatabase.mdb,
with a workgroup security file called c:\a\mysecurity.mdw
using login mylogin,
password mypassword
and connecting to a table called mytable

The content after /head is not really needed - it's used by Internet
Explorer when it tries to open a .odc. As usual, various things can be
removed from the connection string. To use this .odc from Word VBA, all
you should need is

Activedocument.Mailmerge.OpenDataSource _
Name:="the pathname of the .odc"

NB, AFAICR Word/ODS wrongly takes the name of the table to open from the
meta name=Table content=mytable line, which is supposed to be HTML
documentation, instead of the
odc:CommandTextmytable/odc:CommandText line.