View Single Post
  #13   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Connection problem with Access

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.


html

head
meta http-equiv=Content-Type content="text/x-ms-odc; charset=utf-8"
meta name=ProgId content=ODC.Table
meta name=SourceType content=OLEDB
meta name=Table content=mytable
xml id=docpropsoocumentProperties
xmlns="urn:schemas-microsoft-comfficeffice"
xmlns="http://www.w3.org/TR/REC-html40"
oescriptionA short description.../oescription
/oocumentProperties
/xmlxml id=msodcodc:OfficeDataConnection
xmlnsdc="urn:schemas-microsoft-comfficedc"
xmlns="http://www.w3.org/TR/REC-html40"
odc:Connection odc:Type="OLEDB"

odc:ConnectionStringProvider=Microsoft.Jet.OLEDB .4.0;Password=mypassword;User
ID=mylogin;Data Source=c:\a\mydatabase.mdb;Mode=Share Deny None;Extended
Properties="";Jet OLEDB:System
database=c:\a\mysecurity.mdw;Jet OLEDB:Registry Path="";Jet
OLEDBatabase Password="";Jet OLEDB:Engine Type=5;Jet
OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database
Password="";Jet OLEDB:Create System Database=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False/odc:ConnectionString
odc:CommandTypeTable/odc:CommandType
odc:CommandTextmytable/odc:CommandText
/odc:Connection
/odc:OfficeDataConnection
/xml
style
!--
.ODCDataSource
{
behavior: url(dataconn.htc);
}
--
/style

/head

body onload='init()' scroll=no leftmargin=0 topmargin=0 rightmargin=0
style='border: 0px'
table style='border: solid 1px threedface; height: 100%; width: 100%'
cellpadding=0 cellspacing=0 width='100%'
tr
td id=tdName style='font-family:arial; font-size:medium; padding:
3px; background-color: threedface'
 
/td
td id=tdTableDropdown style='padding: 3px; background-color:
threedface; vertical-align: top; padding-bottom: 3px'

 
/td
/tr
tr
td id=tdDesc colspan='2' style='border-bottom: 1px threedshadow
solid; font-family: Arial; font-size: 1pt; padding: 2px;
background-color: threedface'

 
/td
/tr
tr
td colspan='2' style='height: 100%; padding-bottom: 4px;
border-top: 1px threedhighlight solid;'
div id='pt' style='height: 100%' class='ODCDataSource'/div
/td
/tr
/table


script language='javascript'

function init() {
var sName, sDescription;
var i, j;

try {
sName = unescape(location.href)

i = sName.lastIndexOf(".")
if (i=0) { sName = sName.substring(1, i); }

i = sName.lastIndexOf("/")
if (i=0) { sName = sName.substring(i+1, sName.length); }

document.title = sName;
document.getElementById("tdName").innerText = sName;

sDescription = document.getElementById("docprops").innerHTML;

i = sDescription.indexOf("escription")
if (i=0) { j = sDescription.indexOf("escription", i + 11); }

if (i=0 && j = 0) {
j = sDescription.lastIndexOf("/", j);

if (j=0) {
sDescription = sDescription.substring(i+11, j);
if (sDescription != "") {
document.getElementById("tdDesc").style.fontSize=" x-small";
document.getElementById("tdDesc").innerHTML = sDescription;
}
}
}
}
catch(e) {

}
}
/script

/body

/html




Peter Jamieson

http://tips.pjmsn.me.uk

Murray Muspratt-Rouse wrote:
Hi Peter,

I have followed your suggestion, but the system does not like it. I
have deliberately started with a normal Word document and then used the
Word Mail Merge 'wizard'. When I get to 'Select recipients' and browse
for the .odc file I am then shown the contents of the record -
Connection contained SQLStatement and the string contained in quotes
contained SELECT * FROM [mergetable].