Microsoft Office Tutorials and References
In Depth Information
Mail Merge: Creating a One-to-Many List
Option explicit¶
' * * * * *¶
Public MergeEvents As New clsMergeEvents¶
Public BookmarkName As String¶
Public BeforeMergeExecuted As Boolean¶
Public CancelMerge As Boolean¶
Public recordIndex As Long¶
Private DatabasePath As String¶
Private FieldNames() As Variant¶
Private TableName As String¶
Private sepChar As String¶
' * * * * *¶
Sub DoOneToManyMerge()¶
'Preset the global variables¶
BeforeMergeExecuted = False¶
CancelMerge = False¶
recordIndex = 1¶
'Set the user-specific variables¶
Setup¶
'The events in the class module¶
'clsMergeEvents will be enabled¶
ActivateEvents¶
Application.ScreenUpdating = False¶
'As each record is merged¶
'the MailMergeBeforeMerge¶
'event will be called¶
ActiveDocument.MailMerge.Execute¶
'Turn the events off so that they¶
'only execute for this document¶
DeactivateEvents¶
End Sub¶
' * * * * *¶
Sub Setup()¶
'Bookmark target to insert the list¶
BookmarkName = "GradeTable"¶
'Full path to database containing the list¶
DatabasePath = "C:\test\School.mdb"¶
'The table or query with the list information¶
TableName = "Semester Grades"¶
'List the desired fields to show in¶
'the table in the order they should appear¶
'List the ID field name first (it links the data¶
'for the list with the mail merge record)¶
FieldNames() = Array("PupilID", "ClassName", "Grade")¶
'Character to separate the fields' data¶
'that's not present in the field data¶
sepChar = "¦"¶
End Sub¶
Wrd
Search JabSto ::




Custom Search