none
MailMerge In C# Only Shows The First Record RRS feed

  • Question

  •      I'm able to successfully do a mailmerge using a document template manually however when I run my C# code to do the same, I get only one document with the first record's data. I added a loop to iterate through the records and set the ActiveRecord and have successfully retrieved the MergeField names and values but they are not being applied to the new document.

    How can I make it spawn all the documents like the Finish & Merge menu button in word does?

                    while ((Int32)_oMDS.ActiveRecord != _oMDS.RecordCount)
                    {
                        GetMergeFieldData(_oMDS: _oMDS, _iMDFS: _iMDFS);
                        _oMDS.ActiveRecord = Word.WdMailMergeActiveRecord.wdNextRecord;
                        _oWM.DataSource.ActiveRecord = _oMDS.ActiveRecord;
                        _oWM.Execute(Pause: ref oFalse);
                    }
                    GetMergeFieldData(_oMDS: _oMDS, _iMDFS: _iMDFS);
                    _oWM.DataSource.ActiveRecord = _oMDS.ActiveRecord;
                    _oWM.Execute(Pause: ref oFalse);


    DJ Baby Anne's Biggest Fan................

    Thursday, January 8, 2015 4:19 PM

Answers

  • Hi,

    For this issue, the reason is that it uses the first record instead of active record. In my opinion, specify the active record is used for current document.

    So, please specify the first record and last record before execute it.

    _oWM.DataSource.FirstRecord = (int)_oMDS.ActiveRecord;
    _oWM.DataSource.LastRecord = (int)_oMDS.ActiveRecord;

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Abercrombie07 Friday, January 9, 2015 1:58 PM
    Friday, January 9, 2015 8:43 AM
    Moderator

All replies

  • Hi,

    For this issue, the reason is that it uses the first record instead of active record. In my opinion, specify the active record is used for current document.

    So, please specify the first record and last record before execute it.

    _oWM.DataSource.FirstRecord = (int)_oMDS.ActiveRecord;
    _oWM.DataSource.LastRecord = (int)_oMDS.ActiveRecord;

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Abercrombie07 Friday, January 9, 2015 1:58 PM
    Friday, January 9, 2015 8:43 AM
    Moderator
  • Worked like a champ. Thanks.

    DJ Baby Anne's Biggest Fan................

    Friday, January 9, 2015 1:58 PM