S
Sebastian Martinez
Hi,
I have an aplication where I use Automation of Word Mail Merge from SQL
Server, my problem is that the query I use to filter the data from a data
view of the database in SQL Server is longer than 255 characters so I can´t
use the method MailMerge.OpenDataSource.
The solution I´ve found is to make an MailMerge.OpenDataSource without a
query and then set the query using the property
MailMerge.DataSource.QueryString, but it always throw an exception of type
with the message Command failed.
Is there a solution?
Thanks
Here is part of the code:
docApp = new Word.Application();
letterDoc = docApp.Documents.Open(ref docPath, ref missingObject, ref
missingObject,
ref missingObject, ref missingObject, ref missingObject, ref missingObject,
ref missingObject,
ref missingObject, ref missingObject, ref missingObject, ref visible, ref
missingObject,
ref missingObject, ref missingObject, ref missingObject);
object objSQL;
string query;
query = "SELECT * FROM viw_DocumentReport WHERE " + whereClause;
Word.MailMerge letterMerge = letterDoc.MailMerge;
objSQL = (object)query.Trim();
letterMerge.OpenDataSource(ConfigurationSettings.AppSettings["DocumentReport
Conection"].Trim(),
ref missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,
ref missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,
ref missingObject, ref missingObject, ref missingObject, ref missingObject,
ref missingObject);
letterMerge.DataSource.QueryString = query;
letterMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
Word.Document newDocument;
object pause = (object)false;
letterMerge.Check();
letterMerge.Execute(ref pause);
string fileName = "Printed_Document";
newDocument = docApp.ActiveDocument;
newDocument.SaveAs(ref newDocPath, ref missingObject,ref missingObject,ref
missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,ref missingObject,ref missingObject,
ref missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,ref missingObject);
I have an aplication where I use Automation of Word Mail Merge from SQL
Server, my problem is that the query I use to filter the data from a data
view of the database in SQL Server is longer than 255 characters so I can´t
use the method MailMerge.OpenDataSource.
The solution I´ve found is to make an MailMerge.OpenDataSource without a
query and then set the query using the property
MailMerge.DataSource.QueryString, but it always throw an exception of type
with the message Command failed.
Is there a solution?
Thanks
Here is part of the code:
docApp = new Word.Application();
letterDoc = docApp.Documents.Open(ref docPath, ref missingObject, ref
missingObject,
ref missingObject, ref missingObject, ref missingObject, ref missingObject,
ref missingObject,
ref missingObject, ref missingObject, ref missingObject, ref visible, ref
missingObject,
ref missingObject, ref missingObject, ref missingObject);
object objSQL;
string query;
query = "SELECT * FROM viw_DocumentReport WHERE " + whereClause;
Word.MailMerge letterMerge = letterDoc.MailMerge;
objSQL = (object)query.Trim();
letterMerge.OpenDataSource(ConfigurationSettings.AppSettings["DocumentReport
Conection"].Trim(),
ref missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,
ref missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,
ref missingObject, ref missingObject, ref missingObject, ref missingObject,
ref missingObject);
letterMerge.DataSource.QueryString = query;
letterMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
Word.Document newDocument;
object pause = (object)false;
letterMerge.Check();
letterMerge.Execute(ref pause);
string fileName = "Printed_Document";
newDocument = docApp.ActiveDocument;
newDocument.SaveAs(ref newDocPath, ref missingObject,ref missingObject,ref
missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,ref missingObject,ref missingObject,
ref missingObject,ref missingObject,ref missingObject,ref missingObject,ref
missingObject,ref missingObject);