Document.MailMergeBeforeRecordMerge Event (2007 System)
Occurs as a merge is executed for the individual records in a merge.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)
Syntax
'Declaration
Public Event MailMergeBeforeRecordMerge As CancelEventHandler
'Usage
Dim instance As Document
Dim handler As CancelEventHandler
AddHandler instance.MailMergeBeforeRecordMerge, handler
public event CancelEventHandler MailMergeBeforeRecordMerge
public:
event CancelEventHandler^ MailMergeBeforeRecordMerge {
void add (CancelEventHandler^ value);
void remove (CancelEventHandler^ value);
}
JScript does not support events.
Remarks
To stop the mail merge process for the current record, set the Cancel argument of the provided CancelEventArgs to true.
Examples
The following code example displays a message before the first record is merged.
This version is for a document-level customization.
Private Sub DocumentMailMergeBeforeRecordMerge()
AddHandler Me.MailMergeBeforeRecordMerge, AddressOf ThisDocument_MailMergeBeforeRecordMerge
End Sub
Private Sub ThisDocument_MailMergeBeforeRecordMerge(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Dim index As Object = 1
MessageBox.Show(Me.MailMerge.DataSource.DataFields.Item(index).Value & _
" is now merging.")
End Sub
private void DocumentMailMergeBeforeRecordMerge()
{
this.MailMergeBeforeRecordMerge += new System.ComponentModel.CancelEventHandler(ThisDocument_MailMergeBeforeRecordMerge);
}
void ThisDocument_MailMergeBeforeRecordMerge(object sender, System.ComponentModel.CancelEventArgs e)
{
object index = 1;
MessageBox.Show(this.MailMerge.DataSource.DataFields.get_Item(ref index).Value
+ " is now merging.");
}
This version is for an application-level add-in.
Private Sub DocumentMailMergeBeforeRecordMerge()
Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
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 = Me.Application.ActiveDocument.GetVstoObject()
Dim index As Object = 1
System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields.Item(index).Value & _
" is now merging.")
End Sub
private void DocumentMailMergeBeforeRecordMerge()
{
Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
vstoDoc.MailMergeBeforeRecordMerge += new System.ComponentModel.CancelEventHandler(ThisDocument_MailMergeBeforeRecordMerge);
}
void ThisDocument_MailMergeBeforeRecordMerge(object sender, System.ComponentModel.CancelEventArgs e)
{
object index = 1;
Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
System.Windows.Forms.MessageBox.Show(vstoDoc.MailMerge.DataSource.DataFields.get_Item(ref index).Value
+ " is now merging.");
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Office.Tools.Word Namespace
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a version of the code example for an application-level add-in. |
SP1 feature change. |