Posted to microsoft.public.word.mailmerge.fields
|
|
Multiple sub-entries for one main entry
Doug,
The diving alarm is sounded and I am inspired. I will look at this material
further. Thanks.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Doug Robbins - Word MVP wrote:
I thought that "wallowing in dark waters" was what submariners do.
See the "Group Multiple items for a single condition" item on fellow
MVP Cindy Meister's website at
http://homepage.swissonline.ch/cindy...faq1.htm#DBPic
Or take a look at the following Knowledge Base Articles
http://support.microsoft.com/default...b;en-us;302665
http://support.microsoft.com/default...b;en-us;294686
Or, if you create a Catalog (on in Word XP and later, it's called
Directory) type mailmerge main document with the mergefields in the
cells of a one row table in the mailmerge main document with the
keyfield in the first cell in the row and then execute that merge to
a new document and then run the following macro, it will create
separate tables with the records for each key field in them. With a
bit of further development, you may be able to get it to do what you
want.
' Macro to create multiple items per condition in separate tables
from a directory type mailmerge
Dim source As Document, target As Document, scat As Range, tcat As
Range Dim data As Range, stab As Table, ttab As Table
Dim i As Long, j As Long, k As Long, n As Long
Set source = ActiveDocument
Set target = Documents.Add
Set stab = source.Tables(1)
k = stab.Columns.Count
Set ttab = target.Tables.Add(Range:=Selection.Range, numrows:=1,
numcolumns:=k - 1)
Set scat = stab.Cell(1, 1).Range
scat.End = scat.End - 1
ttab.Cell(1, 1).Range = scat
j = ttab.Rows.Count
For i = 1 To stab.Rows.Count
Set tcat = ttab.Cell(j, 1).Range
tcat.End = tcat.End - 1
Set scat = stab.Cell(i, 1).Range
scat.End = scat.End - 1
If scat tcat Then
ttab.Rows.Add
j = ttab.Rows.Count
ttab.Cell(j, 1).Range = scat
ttab.Cell(j, 1).Range.Paragraphs(1).PageBreakBefore = True
ttab.Rows.Add
ttab.Cell(j + 1, 1).Range.Paragraphs(1).PageBreakBefore = False
For n = 2 To k
Set data = stab.Cell(i, n).Range
data.End = data.End - 1
ttab.Cell(ttab.Rows.Count, n - 1).Range = data
Next n
Else
ttab.Rows.Add
For n = 2 To k
Set data = stab.Cell(i, n).Range
data.End = data.End - 1
ttab.Cell(ttab.Rows.Count, n - 1).Range = data
Next n
End If
Next i
"Greg Maxey" wrote in message
...
Thanks Peter.
It doesn't appear to be a straight forward process. Since it was
just a whim, I don't think that I am prepared to go wallowing into
dark waters. Cheers
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
"Peter Jamieson" wrote in message
...
Hi Greg,
Mailmerge is not really up to this kind of "one-to-many" task. It is
possible to do some stuff - e.g. have a look at CIndy Meister's
site at http://homepage.swissonline.ch/cindymeister/, specifically
the Mail Merge FAQ, Special merges, "Multiple items per condition".
For the specific example you mention, I'd be more inclined to do a
first pass of some kind, possibly using VBA and ADO to generate the
data source I really needed - i.e. probably one which had one
record for each name in column A and the exact text I wanted to
stuff in in another column. Peter Jamieson
"Greg Maxey" wrote in message
...
Mailmerge is definitely not my strong suit. I became curious today
to learn how to do a specific task.
Say I have an Excel spread sheet with names in column A
and some other data in column B. Because there can be one or more
data elements in Column B, some of the A cells are blank. Like
this: Name Fav Color
Fred Red
White
Blue
Bill Green
Yellow
Mary Purple
Gold
Could I use this construction in some way to create a mailmerge
like: Dear Fred,
Your favority colors are red, white, and blue
Dear Bill
Your favorite colors are green and yellow.
Etc.
If not, how would I have to layout the datasource to achieve this.
Thanks.
|