If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Mail merge fields
I am creating a confirmation document and would like to have attendees from
the same company listed in the body of the confirmation without having to use the query function in merge. I tried using "next record" but that added attendees from another company. What I would like is one sheet per company with a listing of the attendees (there are two-three per company). I tried having the document be a form letter and a catalog. The result wasn't want I wanted. I'm using Word 2000. Thanks for any help or direction you can give me. -pam |
#2
|
|||
|
|||
I just did something like this, and since word mail merge is built as a
one to one replacement of data with fields, not repeating data, you need to get a little tricky with VBA. Basically, what I did was handle the MailMergeAfterRecordMerge and MailMergeBeforeRecordMerge events in the mail merge document template. In the MailMergeAfterRecordMerge I check the datasource values to see if I need to add any values to a table, if I do, then I add those values while getting the next record until I detect that I have come to the next data element that needs to be merged. Below I've included the full source code, it works great - oh, and you need to handle the MailMergeBeforeRecordMerge because as you advance to the next element in your datasource the damn thing will try and fire the merge even though you are currently in the event to handle it! ' Global variables Public WithEvents MailMergeApp As Word.Application Public ActDoc As Document Public NewDoc As Document Public CancelMerge As Boolean Private Sub MailMergeApp_MailMergeAfterRecordMerge(ByVal Doc As Document) Dim mergeDataTable As Table Dim mergeData As MailMergeDataSource Dim eventId As Integer Dim nextEventId As Integer Dim g As Integer If ActDoc Is Nothing Then For g = 1 To MailMergeApp.Documents.Count If MailMergeApp.Documents(g).Name = "ClientSummaryLetter.doc" Then Set ActDoc = MailMergeApp.Documents(g) End If If MailMergeApp.Documents(g).Name "ClientSummaryLetter.doc" And _ MailMergeApp.Documents(g).Name "mergedatasource.doc" Then Set NewDoc = MailMergeApp.Documents(g) End If Next End If For g = 1 To NewDoc.Tables.Count If NewDoc.Tables(g).Rows.Count = 1 Then Set mergeDataTable = NewDoc.Tables(g) Exit For End If Next Set mergeData = ActDoc.MailMerge.DataSource eventId = CInt(ActDoc.MailMerge.DataSource.DataFields(8).Val ue) nextEventId = CInt(ActDoc.MailMerge.DataSource.DataFields(8).Val ue) CancelMerge = True While eventId = nextEventId newrow = mergeDataTable.Rows.Add() mergeDataTable.Cell(mergeDataTable.Rows.Count, 1).Range.InsertAfter (mergeData.DataFields(9).Value) mergeDataTable.Cell(mergeDataTable.Rows.Count, 2).Range.InsertAfter (mergeData.DataFields(10).Value) mergeDataTable.Cell(mergeDataTable.Rows.Count, 3).Range.InsertAfter (mergeData.DataFields(11).Value) mergeDataTable.Cell(mergeDataTable.Rows.Count, 4).Range.InsertAfter (mergeData.DataFields(12).Value) ActDoc.MailMerge.DataSource.ActiveRecord = wdNextRecord If IsNumeric(ActDoc.MailMerge.DataSource.DataFields(8 ).Value) Then nextEventId = CInt(ActDoc.MailMerge.DataSource.DataFields(8).Val ue) Else Exit Sub End If Wend CancelMerge = False End Sub Private Sub MailMergeApp_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean) If CancelMerge Then Cancel = True End If End Sub _Randal |
#3
|
|||
|
|||
Thanks. I'll give this try.
"Pam in California" wrote: I am creating a confirmation document and would like to have attendees from the same company listed in the body of the confirmation without having to use the query function in merge. I tried using "next record" but that added attendees from another company. What I would like is one sheet per company with a listing of the attendees (there are two-three per company). I tried having the document be a form letter and a catalog. The result wasn't want I wanted. I'm using Word 2000. Thanks for any help or direction you can give me. -pam |
#4
|
|||
|
|||
Word isn't designed to do this. In consequence, however you do it, it can be
hard to get it right. Some approaches are described at http://homepage.swissonline.ch/cindymeister/ Look for Mail Merge FAQ, Special Merges, Multiple items per condition. Peter Jamieson "Pam in California" wrote in message ... I am creating a confirmation document and would like to have attendees from the same company listed in the body of the confirmation without having to use the query function in merge. I tried using "next record" but that added attendees from another company. What I would like is one sheet per company with a listing of the attendees (there are two-three per company). I tried having the document be a form letter and a catalog. The result wasn't want I wanted. I'm using Word 2000. Thanks for any help or direction you can give me. -pam |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How can I mail merge a .csv file, matching fields, into a Word doc | Fluffy from Wisconsin | General Discussion | 3 | May 19th, 2005 01:38 PM |
Access not filling in form fields in mail merge | Tom Knapp | General Discussion | 2 | May 5th, 2005 05:18 PM |
Empty Mail Merge Fields | Meggan | General Discussion | 1 | January 13th, 2005 05:22 AM |
mail merge with attachments | AS | Mailmerge | 3 | December 21st, 2004 04:11 AM |
blank fields in mail merge | Sonya | Publisher | 2 | September 8th, 2004 10:11 PM |