Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
nuno_fbo[_2_] nuno_fbo[_2_] is offline
external usenet poster
 
Posts: 4
Default How to get specific data from a datasorce to a mailmerge doc? SQL

Hi,

PS: Look into this close situation:
http://www.experts-exchange.com/Prog..._21767403.html

I was looking for information to resolve a little problem that I'm having
and I saw this topic hear and I hope if you can help me

I have a event im my page page.aspx.cs


I tried to run the code that I writed and I have an Error in he

docWord.MailMerge.DataSource.QueryString = "SELECT [intnome] FROM
[intervenientes] WHERE [intid] = 2";
The message error is: {"Command failed"}

If I comment this line I don't have any problem with my process.. It merge a
new .doc, but with all data from the table intervinientes... and I want to
get specic data...

I hope to get any information about this question...

Anyone who did something like this before... Did a process in C# and merge a
document with specific data from a SQL Server data source...

How can I do a SQL command only to merge specific .doc?
That is all my event code:

void testeWord()
{
String data = DateTime.Today.ToShortDateString();
string utilizador = HttpContext.Current.User.Identity.Name.ToString();

object objMiss = Type.Missing;
object ficheiroOrigem = "C:\\Documents and Settings\\Nuno
Oliveira\\My Documents\\Nuno Oliveira\\CV\\mailmerge.doc";
object ficheiroDest = "C:\\Documents and Settings\\Nuno Oliveira\\My
Documents\\Nuno Oliveira\\CV\\MailMerge" + utilizador + "." + data + ".doc";
object objTrue = true;
object objFalse = false;
Microsoft.Office.Interop.Word.Document docWord;

//open Microsoft Word

Microsoft.Office.Interop.Word.ApplicationClass appWord = new
Microsoft.Office.Interop.Word.ApplicationClass();
appWord.Visible = false;


//open Template file
docWord = appWord.Documents.Open(ref ficheiroOrigem,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss,
ref objMiss);
docWord.Select();

//open datasource
object format =
Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenF ormatText;
string source = "C:\\Documents and Settings\\Nuno Oliveira\\My
Documents\\My Data Sources\\localhost mba_testes intervenientes.odc";
docWord.MailMerge.OpenDataSource(source, ref format, ref objFalse,
ref objMiss, ref objTrue,
ref objFalse, ref objMiss, ref objMiss, ref objMiss, ref
objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss);


docWord.MailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
docWord.MailMerge.SuppressBlankLines = true;
docWord.MailMerge.DataSource.QueryString = "SELECT [intnome] FROM
[intervenientes] WHERE [intid] = 2";
docWord.MailMerge.DataSource.FirstRecord =
(int)Microsoft.Office.Interop.Word.WdMailMergeDefa ultRecord.wdDefaultFirstRecord;
docWord.MailMerge.DataSource.LastRecord =
(int)Microsoft.Office.Interop.Word.WdMailMergeDefa ultRecord.wdDefaultLastRecord;
docWord.MailMerge.Execute(ref objFalse);


appWord.ActiveDocument.SaveAs(ref ficheiroDest,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss);

docWord.Close(ref objFalse, ref objMiss, ref objMiss);

appWord.Visible = true;
appWord.ShowMe();
//appWord.Quit(null, null, null);

//Server.Transfer(@"\\localhost\C:\Documents and Settings\Nuno
Oliveira\My Documents\Nuno Oliveira\CV\rESULTADOmAILmERGE.DOC");
}

Canyou help me

Thank you for your attencion...

Regards,
Nuno Oliveira

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default How to get specific data from a datasorce to a mailmerge doc? SQL

Replied to your other similar message.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"nuno_fbo" wrote in message
...
Hi,

PS: Look into this close situation:
http://www.experts-exchange.com/Prog..._21767403.html

I was looking for information to resolve a little problem that I'm having
and I saw this topic hear and I hope if you can help me

I have a event im my page page.aspx.cs


I tried to run the code that I writed and I have an Error in he

docWord.MailMerge.DataSource.QueryString = "SELECT [intnome] FROM
[intervenientes] WHERE [intid] = 2";
The message error is: {"Command failed"}

If I comment this line I don't have any problem with my process.. It merge
a
new .doc, but with all data from the table intervinientes... and I want to
get specic data...

I hope to get any information about this question...

Anyone who did something like this before... Did a process in C# and merge
a
document with specific data from a SQL Server data source...

How can I do a SQL command only to merge specific .doc?
That is all my event code:

void testeWord()
{
String data = DateTime.Today.ToShortDateString();
string utilizador = HttpContext.Current.User.Identity.Name.ToString();

object objMiss = Type.Missing;
object ficheiroOrigem = "C:\\Documents and Settings\\Nuno
Oliveira\\My Documents\\Nuno Oliveira\\CV\\mailmerge.doc";
object ficheiroDest = "C:\\Documents and Settings\\Nuno Oliveira\\My
Documents\\Nuno Oliveira\\CV\\MailMerge" + utilizador + "." + data +
".doc";
object objTrue = true;
object objFalse = false;
Microsoft.Office.Interop.Word.Document docWord;

//open Microsoft Word

Microsoft.Office.Interop.Word.ApplicationClass appWord = new
Microsoft.Office.Interop.Word.ApplicationClass();
appWord.Visible = false;


//open Template file
docWord = appWord.Documents.Open(ref ficheiroOrigem,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss,
ref objMiss);
docWord.Select();

//open datasource
object format =
Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenF ormatText;
string source = "C:\\Documents and Settings\\Nuno Oliveira\\My
Documents\\My Data Sources\\localhost mba_testes intervenientes.odc";
docWord.MailMerge.OpenDataSource(source, ref format, ref objFalse,
ref objMiss, ref objTrue,
ref objFalse, ref objMiss, ref objMiss, ref objMiss, ref
objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss);


docWord.MailMerge.Destination =
Microsoft.Office.Interop.Word.WdMailMergeDestinati on.wdSendToNewDocument;
docWord.MailMerge.SuppressBlankLines = true;
docWord.MailMerge.DataSource.QueryString = "SELECT [intnome] FROM
[intervenientes] WHERE [intid] = 2";
docWord.MailMerge.DataSource.FirstRecord =
(int)Microsoft.Office.Interop.Word.WdMailMergeDefa ultRecord.wdDefaultFirstRecord;
docWord.MailMerge.DataSource.LastRecord =
(int)Microsoft.Office.Interop.Word.WdMailMergeDefa ultRecord.wdDefaultLastRecord;
docWord.MailMerge.Execute(ref objFalse);


appWord.ActiveDocument.SaveAs(ref ficheiroDest,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref objMiss, ref
objMiss,
ref objMiss, ref objMiss, ref objMiss, ref objMiss);

docWord.Close(ref objFalse, ref objMiss, ref objMiss);

appWord.Visible = true;
appWord.ShowMe();
//appWord.Quit(null, null, null);

//Server.Transfer(@"\\localhost\C:\Documents and Settings\Nuno
Oliveira\My Documents\Nuno Oliveira\CV\rESULTADOmAILmERGE.DOC");
}

Canyou help me

Thank you for your attencion...

Regards,
Nuno Oliveira


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert data into a specific cell in a table? vincent Tables 0 July 24th 07 03:48 AM
Extracting specific Excel data into word Nicole Knapp Microsoft Word Help 3 July 12th 07 10:18 PM
Importing Data to specific Fields in a Word Document Phil Adler Microsoft Word Help 8 January 10th 07 03:23 PM
Searching for specific data in specific column ll Tables 1 December 3rd 05 08:38 PM
How do I select specific data from an imported document smintey Microsoft Word Help 1 December 6th 04 02:28 PM


All times are GMT +1. The time now is 06:50 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"