Document.MailMergeBeforeRecordMerge Event

 

Occurs as a merge is executed for the individual records in a merge.

Namespace:   Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

event CancelEventHandler MailMergeBeforeRecordMerge

To stop the mail merge process for the current record, set the Cancel argument of the provided CancelEventArgs to true.

The following code example displays a message before the first record is merged. This example is for an application-level add-in.

private void DocumentMailMergeBeforeRecordMerge()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.MailMergeBeforeRecordMerge += new System.ComponentModel.CancelEventHandler(ThisDocument_MailMergeBeforeRecordMerge);
}

void ThisDocument_MailMergeBeforeRecordMerge(object sender, System.ComponentModel.CancelEventArgs e)
{
    object index = 1;
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields[index].Value + 
         " is now merging.");
}
Return to top
Show: