J
Jason W Taylor
My vb.net traditional client application needs to automate Word
mailmerge documents across multiple versions of Office (2000 and
later). The application comes with pre-defined .doc files that are
used as "reports". The data comes from an Access 2000 database.
Recently I have discovered that my existing code does not work as well
with Word 2002, because of problems I have seen discussed extensively
in this NG by MVP Cindy. While my code generates a mailmerged document
nicely with Word 2000 installed, I am unable to prevent display of the
"Data Link Properties" dialog if Word 2002 is installed. We are trying
to get this problem to go away, as our users will be blown away by it,
and unable to recover from the psychological damage inflicted by a
series of very technical dialogs.
None of the solutions I have seen posted have fixed my problem. One of
which was defining the SubType. This is not a viable solution anyway,
I need a backward compatible solution, and I understand the parameter
is not supported by Word 2000. We tried it anyway for fun, and it has
no effect.
Here is the VB.net code that automates the merge, based on a query of
an Access DB.
....
' Create an instance of Word
oWrdApp = CreateObject("Word.Application")
oWrdApp.Visible = False
' sTemplateFileName contains a path to a predefined merge
template
oWrdDoc =
oWrdApp.Documents.Open(FileName:=sTemplateFileName)
oWrdDoc.Select()
wrdSelection = oWrdApp.Selection()
wrdMailMerge = oWrdDoc.MailMerge()
oWrdDoc.MailMerge.OpenDataSource( [a string with the full
path to the database file get passed here], _
Connection:=sConstr, SQLStatement:="SELECT * FROM SomeTable WHERE
TableID = " & nID)
wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument
wrdMailMerge.Execute(False)
....
here is what my connection string variable contains:
Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data
Source=somedatabase.mdb;Mode=Share Deny None;Jet OLEDBatabase
Password=databasepassword;Jet OLEDB:Engine Type=5;Jet OLEDBatabase
Locking Mode=1;
NOTE:
We are using a database password to secure the database and keep the
users out of it.
We have also tried an ODBC style connection string, which also causes
the Data Link Properties to rear its ugly head, but there are no
subsequent dialogs, and the merge goes on to actually work and the
merge fields are populated. This connection string looks like this:
"DSN=MS Access Database;DBQ=(full path to the .mdb file here);FIL=MS
Access;UID=Admin;PWD=databasepassword;DriverId=25;MaxBufferSize=2048;PageTimeout=5;"
From what I understand, it is not a great idea to create a dependency
on ODBC at this point.
Any thoughts or ideas? I will happily write differing code for the
existing version by detecting it in the registry in some manner, but
so far I can't get Word 2002 to work without displaying some kind of
dialogs. I Haven't even gotten through testing it to find out what
nightmares await in Office 2003.
Thanks.
Jason W. Taylor, MCSD
CODE AUTHORITY, INC
http://www.codeauthority.com
Microsoft Certified Partner
mailmerge documents across multiple versions of Office (2000 and
later). The application comes with pre-defined .doc files that are
used as "reports". The data comes from an Access 2000 database.
Recently I have discovered that my existing code does not work as well
with Word 2002, because of problems I have seen discussed extensively
in this NG by MVP Cindy. While my code generates a mailmerged document
nicely with Word 2000 installed, I am unable to prevent display of the
"Data Link Properties" dialog if Word 2002 is installed. We are trying
to get this problem to go away, as our users will be blown away by it,
and unable to recover from the psychological damage inflicted by a
series of very technical dialogs.
None of the solutions I have seen posted have fixed my problem. One of
which was defining the SubType. This is not a viable solution anyway,
I need a backward compatible solution, and I understand the parameter
is not supported by Word 2000. We tried it anyway for fun, and it has
no effect.
Here is the VB.net code that automates the merge, based on a query of
an Access DB.
....
' Create an instance of Word
oWrdApp = CreateObject("Word.Application")
oWrdApp.Visible = False
' sTemplateFileName contains a path to a predefined merge
template
oWrdDoc =
oWrdApp.Documents.Open(FileName:=sTemplateFileName)
oWrdDoc.Select()
wrdSelection = oWrdApp.Selection()
wrdMailMerge = oWrdDoc.MailMerge()
oWrdDoc.MailMerge.OpenDataSource( [a string with the full
path to the database file get passed here], _
Connection:=sConstr, SQLStatement:="SELECT * FROM SomeTable WHERE
TableID = " & nID)
wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument
wrdMailMerge.Execute(False)
....
here is what my connection string variable contains:
Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data
Source=somedatabase.mdb;Mode=Share Deny None;Jet OLEDBatabase
Password=databasepassword;Jet OLEDB:Engine Type=5;Jet OLEDBatabase
Locking Mode=1;
NOTE:
We are using a database password to secure the database and keep the
users out of it.
We have also tried an ODBC style connection string, which also causes
the Data Link Properties to rear its ugly head, but there are no
subsequent dialogs, and the merge goes on to actually work and the
merge fields are populated. This connection string looks like this:
"DSN=MS Access Database;DBQ=(full path to the .mdb file here);FIL=MS
Access;UID=Admin;PWD=databasepassword;DriverId=25;MaxBufferSize=2048;PageTimeout=5;"
From what I understand, it is not a great idea to create a dependency
on ODBC at this point.
Any thoughts or ideas? I will happily write differing code for the
existing version by detecting it in the registry in some manner, but
so far I can't get Word 2002 to work without displaying some kind of
dialogs. I Haven't even gotten through testing it to find out what
nightmares await in Office 2003.
Thanks.
Jason W. Taylor, MCSD
CODE AUTHORITY, INC
http://www.codeauthority.com
Microsoft Certified Partner