Application.MailMergeGenerateBarcode event (Publisher)

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

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 the 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.

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.

Public WithEvents pubApplication As Application

You then must run the following initialization procedure.

Public Sub Initialize_pubApplication() 
 Set pubApplication = Publisher.Application 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.