Multiple sub-entries for one main entry

G

Greg Maxey

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.
 
P

Peter Jamieson

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

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.
 
G

Greg Maxey

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
 
D

Doug Robbins - Word MVP

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/cindymeister/mergfaq1.htm#DBPic


Or take a look at the following Knowledge Base Articles

http://support.microsoft.com/default.aspx?scid=kb;en-us;302665


http://support.microsoft.com/default.aspx?scid=kb;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


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Greg Maxey

Doug,

The diving alarm is sounded and I am inspired. I will look at this material
further. Thanks.
 
G

Greg

Doug,

Cracked it!!! Thanks for the nudge.

I adpated the Q211303 method as follows to meet my needs:

{ SET Name1 { MF Name }}{ IF { MERGESEQ } = "1""{ IF { Name1 } =
"""<enter>
{ MF Donations }"<enter>
"Name: { MF Name } Address: { MF Address }<enter>
<enter>
{ MF Donations }"} ""{ IF { Name1 } = """<enter>
{ MF Donations }"<enter>
"<enter>
<Page Break>
Name: { MF Name } Address: { MF Address }<enter>
<enter>
{ MF Donations }"} " }<enter>

MF stands in for the full text MERGEFIELD in the actual field code.

This works for an EXCEL spreadsheet laid out as:

Name Address Donations
Bill Miller 123 Cherry St. $60.00
$40.00
$25.00
Mary Poppins 456 Pine St. $100.00
$50.00
Tom Sawyer ....

where the blank spaces are empter mergefields.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top