word Mail merge

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • YY

    word Mail merge

    For some reason my word mail merge throws execption when it reaches
    wrdMailMerge = oDataDoc.MailMe rge.

    Can any body guide me in a clean wasy of doing mailerge from sql server 2005
    table ? I really appreciate your help. Below is the code I tried hundred
    times but throws exception.


    try
    {
    Word.Applicatio n wrdApp;
    Word.Document oDataDoc;
    Word.MailMerge wrdMailMerge;
    Object oMissing = System.Type.Mis sing;
    Object oFalse = false;
    Object oTrue = true;
    Object oName = "c:\\templatefi le.dot";
    Object oFileName = "c"\\outputfile .doc";
    Object oFileFormat = Word.WdSaveForm at.wdFormatRTF;
    Object oConnection = "Data Source=sand01;C atalog=mydataba se;Integrated
    Security=SSPI"; ;
    Object oQuery = "select * from mytable" ;
    Object oSubType = Word.WdMergeSub Type.wdMergeSub TypeWord;
    wrdApp = new Word.Applicatio nClass();
    wrdApp.Visible = true;
    wrdApp.WindowSt ate = Word.WdWindowSt ate.wdWindowSta teMaximize;
    oDataDoc = wrdApp.Document s.Add(ref oName, ref oFalse, ref oMissing, ref
    oMissing);
    oDataDoc.Activa te();
    wrdMailMerge = oDataDoc.MailMe rge;
    wrdMailMerge.Hi ghlightMergeFie lds = false;
    wrdMailMerge.Vi ewMailMergeFiel dCodes = 0;
    wrdMailMerge.Op enDataSource("" , ref oFileFormat, ref oMissing, ref oMissing,
    ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oFalse, ref
    oMissing, ref oMissing, ref oConnection, ref oQuery, ref oMissing, ref
    oMissing, ref oSubType);
    wrdMailMerge.Su ppressBlankLine s = true;
    oDataDoc.SaveAs (ref oFileName, ref oFileFormat, ref oMissing, ref oMissing,
    ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
    oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
    oMissing, ref oMissing);
    oDataDoc.Saved = true;
    // Unload objects from the memory
    wrdMailMerge = null;
    oDataDoc = null;
    wrdApp = null;
    }
    catch (Exception exc)
    {
    }

Working...