Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Mail Merge word 2010

$
0
0

attempting to open a word 2010 doc and start mail merge process

having trouble with MailMerge.OpenDataSource

i need the users to select the criteria then run the merge from a windows form

i have tried many ways , the closest is by following code:

  string SQLConn1 = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=warehousing;Data Source=dct-kwy-sosql1;";                

Object oMissing = System.Reflection.Missing.Value;
                Object oTrue = true;
                Object oFalse = false;
                Word.Application oWord = new Word.Application();
                Word.Document oWordDoc = new Word.Document();
                oWord.Visible = true;
                Object oTemplatePath = path;
                oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

                oWordDoc.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters;                    

  oWordDoc.MailMerge.OpenDataSource(Name: "",ConfirmConversions:false,ReadOnly:false,LinkToSource:true,AddToRecentFiles:false,Revert:false,
                    Connection:SQLConn1,SQLStatement:"SELECT *  FROM vwRenewalLetters");



                oWordDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument;
                oWordDoc.MailMerge.Execute();
the doc opens with the following dialog

when i click ok Visual studio shows error:


any thoughts?

Grant



Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>