MailMergeBeforeMerge Event

Microsoft Publisher Visual Basic

Private Sub object_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)

object    A variable which references an object of type Application declared with events in a class module.

Doc Required. The mail merge main document.

StartRecord Required. The first record in the data source to include in the mail merge.

EndRecord Required. The last record in the data source to include in the mail merge.

Cancel Optional. True stops the mail merge process before it starts.

Remarks

To access the Application object events, declare an Application object variable in the General Declarations section of a code module. Then set the variable equal to the Application object for which you want to access events. For information about using events with the Publisher Application object, see Using Events with the Application Object.

Example

This example displays a message before the mail merge process begins, asking the user if they want to continue. If the user clicks No, the merge process is cancelled.

Private Sub MailMergeApp_MailMergeBeforeMerge(ByVal Doc As Document, _
    ByVal StartRecord As Long, ByVal EndRecord As Long, _
    Cancel As Boolean)

    Dim intVBAnswer As Integer

    Set Doc = ActiveDocument

    'Request whether the user wants to continue with the merge
    intVBAnswer = MsgBox("Mail Merge for " & Doc.Name & _
        " is now starting.  Do you want to continue?", _
        vbYesNo, "Event!")

    'If user's response to question was No, then cancel merge process
    'and deliver a message to the user stating the merge is cancelled
    If intVBAnswer = vbNo Then
        Cancel = True
        MsgBox "You have cancelled mail merge for " & _
            Doc.Name & "."
    End If

End Sub
		

For this event to occur, you must place the following line of code in the General Declarations section of your module and run the following initialization routine.

Private WithEvents MailMergeApp As Application

Sub InitializeMailMergeApp()
    Set MailMergeApp = Publisher.Application
End Sub