Word2003 Mail Merge with SQLServer2000

K

Kingsley

I'm having problems opening a datasource from SQLServer 2000 to be used for a
mail merge word 2003. Each time I run the code below, I get an error message
saying "datasource can not be opened".

object oFile = System.Environment.CurrentDirectory + "\\Document.doc";
object SubType = WdMergeSubType.wdMergeSubTypeOLEDBWord;
WordDoc = WordApp.Documents.Open(ref oFile,ref Unknown,...,ref Unknown)
object sDBConnection = "server=localhost;database=Northwind;Integrated
Security=SSPI;";
object query = "Select CompanyName,Address,City,Country,ContactName from
Customers where CustomerID='ALFI'";

WordDoc.MailMerge.OpenDataSource(DSName,ref format,ref Unknown,ref
Unknown,ref TRUE,ref Unknown, ref Unknown,ref Unknown,ref Unknown,ref
Unknown,ref Unknown,ref sDBConnection,ref query,ref Unknown,ref Unknown,ref
SubType);

Please help...
 
P

Peter Jamieson

What is in DSName? For this to work, it will probably need to be a .udl file
or a .odc file, unless you want to open the connection using ODBC. The .odc
file can be completely empty as long as all the necessary connection
information is passed in the OpenDataSource call's connection parameter. In
this case, it should start with the name of the OLEDB provider, e.g.

Provider=providername (sorry,I do not have the details to hand)

You may alsofindthat using a table alias in the SQLstatement jhelps, e.g.
instead of

"Select CompanyName,Address,City,Country,ContactName from Customers where
CustomerID='ALFI'"

try

"Select C.CompanyName,C.Address,C.City,C.Country,C.ContactName from
Customers C where C.CustomerID='ALFI'"

Peter Jamieson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top