Freigeben über


Document.MailMergeBeforeRecordMerge Event

Definition

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

public:
 event System::ComponentModel::CancelEventHandler ^ MailMergeBeforeRecordMerge;
event System.ComponentModel.CancelEventHandler MailMergeBeforeRecordMerge;
member this.MailMergeBeforeRecordMerge : System.ComponentModel.CancelEventHandler 
Event MailMergeBeforeRecordMerge As CancelEventHandler 

Event Type

Examples

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.");
}
Private Sub DocumentMailMergeBeforeRecordMerge()
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    AddHandler vstoDoc.MailMergeBeforeRecordMerge, AddressOf ThisDocument_MailMergeBeforeRecordMerge
End Sub

Private Sub ThisDocument_MailMergeBeforeRecordMerge(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    Dim index As Object = 1
    System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields.Item(index).Value & _
      " is now merging.")
End Sub

Remarks

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

Applies to