Share via


Application.MailMergeGenerateBarcode Event

Publisher Developer Reference

Occurs when Microsoft Office Publisher requires data to generate barcodes in a mail-merge publication, in particular when the mail-merge recipient list changes.

Version Information
 Version Added:  Publisher 2007

Syntax

expression.MailMergeGenerateBarcode(Doc, bstrString)

expression   A variable that represents an Application object.

Parameters

Name Required/Optional Data Type Description
Doc Required Document The current publication.
bstrString Required String Output parameter. A string representation of the barcode.

Remarks

Third-party add-ins that validate mail-merge addresses can use the MailMergeGenerateBarcode event to listen for user actions requesting that barcodes be generated. In this situation, when the add-in receives notification that the MailMergeGenerateBarcode event fired, and if the active document is connected to a data source, the add-in can use the MailMergeDataSource.ActiveRecord property to determine the record for which to generate the barcode. If the active document is not connected to a data source, the add-in uses the address text directly.

If the add-in can use the address text directly, it returns a string representation of the barcode for the bstrString output parameter. If the add-in cannot use the address text directly, it returns an empty string.

To permit triggering of the MailMergeGenerateBarcode event, you must handle the MailMergeInsertBarcode event in your code, and the add-in must set the OkToInsert parameter passed to that event to True.

For more information about using events with the Application object, see Using Events with the Application Object.

Example

The following Microsoft Visual Basic for Applications (VBA) macro shows how to handle the MailMergeGenerateBarcode event. It returns the string that represents the barcode for active record. Note that the variable indexNumberOfBarcodeColumn represents the index number of the column in the data source that lists barcodes. This code assumes that the current publication is connected to a data source.

Visual Basic for Applications
  Private Sub pubApplication_MailMergeGenerateBarcode(ByVal Doc As Document, bstrString As String)
    bstrString = pubApplication.ActiveDocument.MailMerge.DataSource.DataFields.Item(indexNumberOfBarcodeColumn).Value
End Sub

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

Visual Basic for Applications
  Public WithEvents pubApplication As Application

Then run the following initialization procedure.

Visual Basic for Applications
  Public Sub Initialize_pubApplication()
    Set pubApplication = Publisher.Application
End Sub

See Also