Reply
 
Thread Tools Display Modes
  #1   Report Post  
Pam in California
 
Posts: n/a
Default 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   Report Post  
 
Posts: n/a
Default

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   Report Post  
Pam in California
 
Posts: n/a
Default

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   Report Post  
Peter Jamieson
 
Posts: n/a
Default

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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mail merge with attachments AS Mailmerge 5 April 9th 05 09:49 AM
Splitting text from mail merge fields Mark Ainsworth Mailmerge 1 March 29th 05 08:34 PM
Empty Mail Merge Fields Meggan Microsoft Word Help 1 January 13th 05 05:22 AM
Empty Mail Merge Fields Meggan Microsoft Word Help 0 January 13th 05 12:43 AM
mail merge problem - "Word found locked fields during the update.. zgaryt Tables 1 January 9th 05 01:04 PM


All times are GMT +1. The time now is 07:06 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"