A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Mail merge fields



 
 
Thread Tools Display Modes
  #1  
Old April 20th, 2005, 10:03 PM
Pam in California
external usenet poster
 
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  
Old April 21st, 2005, 12:06 AM
external usenet poster
 
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  
Old April 21st, 2005, 12:25 AM
Pam in California
external usenet poster
 
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  
Old April 21st, 2005, 08:09 AM
Peter Jamieson
external usenet poster
 
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



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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 06:22 AM
mail merge with attachments AS Mailmerge 3 December 21st, 2004 05:11 AM
blank fields in mail merge Sonya Publisher 2 September 8th, 2004 10:11 PM


All times are GMT +1. The time now is 02:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.