Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / November 2004

Tip: Looking for answers? Try searching our database.

Loops

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Monika Krug - 10 Nov 2004 11:40 GMT
Is it possible to have some kind of loop or recursion with
mail merge fields?

Somewhat like this:

{ SET total { MERGEFIELD number }}
{ SET index 1 }
{ WHILE { index } < { total }
 { MERGEFIELD "Name{index}" }
 { SET index { = index + 1 } }
}

Or any kind of workaround that achieves the same?

Monika.
Paul Lautman - 10 Nov 2004 17:27 GMT
> Is it possible to have some kind of loop or recursion with
> mail merge fields?
[quoted text clipped - 11 lines]
>
> Monika.

In trying to assist in this I have to ask why you wish to do this. There may
be another way to accomplish what you wish.
Cindy M  -WordMVP- - 10 Nov 2004 20:33 GMT
Hi Monika,

There's a discussion about one-to-many types of mail merge on
my website (multiple items / record). I'm not sure if this is
what you want, but there is a link to a KB article that
describes how to set up such a loop.

> Is it possible to have some kind of loop or recursion with
> mail merge fields?
[quoted text clipped - 9 lines]
>  
> Or any kind of workaround that achieves the same?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun
8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)
Monika Krug - 11 Nov 2004 09:40 GMT
Cindy Meister writes:

>There's a discussion about one-to-many types of mail merge on
>my website (multiple items / record). I'm not sure if this is
>what you want, but there is a link to a KB article
>[http://support.microsoft.com/?kbid=105888] that
>describes how to set up such a loop.

I have read those, and your website as well as the KB
article were very helpful in getting to the point where I
am at now.

The problem is with: "with a copy of the conditional
statements equal to the maximum number of projects for
each employee". I have an estimate of typically 1 to 4
records, so I have inserted the statements five times ...
but maybe there could be more, so I wondered if there is a
way (without macros) to duplicate them a certain number of
times that is read from the data source. Also, the copying
is verbose and error-prone when making changes. But I
guess there is no other solution.

I have now inserted a conditional statement that prints
out a warning that all the following data will be
corrupted when there are too many records.

Monika.
Cindy M  -WordMVP- - 11 Nov 2004 13:21 GMT
Hi Monika,

Either I'm not understanding you, or you haven't quite
grasped the everything in the KB article. The article does
show you how to set up a looping sequence. But you have to
have the data set up the right way:

EmployeeID, ProjectDetail
EmployeeED, ProjectDetail

Sorted by EmployeeID. When you do this, the mail merge will
process each record in turn. The SET field notes the current
Employee ID. Within the IF field you have both the text for
the repeating data (project), as well as the text that
preceeds and follows the repeated listing. As long as the
EmployeeID doesn't change, the list is repeated. When it
changes, the other text is inserted (including the first item
in the list).

> The problem is with: "with a copy of the conditional
> statements equal to the maximum number of projects for
[quoted text clipped - 5 lines]
> is verbose and error-prone when making changes. But I
> guess there is no other solution.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun
8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)
Monika Krug - 11 Nov 2004 14:32 GMT
Cindy Meister wrote:

>Hi Monika,
>
[quoted text clipped - 14 lines]
>changes, the other text is inserted (including the first item
>in the list).

I understand that, and that is also what I have done. As I
said in my last post: The problem I tried to solve was
that the maximum number of projects per employee needs to
be known beforehand and the statements need to be copied
that often.

Monika.

---

>> The problem is with: "with a copy of the conditional
>> statements equal to the maximum number of projects for
[quoted text clipped - 16 lines]
>
>.
Cindy M  -WordMVP- - 12 Nov 2004 11:28 GMT
Hi Monika,

> As I
> said in my last post: The problem I tried to solve was
> that the maximum number of projects per employee needs to
> be known beforehand and the statements need to be copied
> that often.

Yes, that's where we're not communicating. If the data is
set up so that it simply lists the projects, as far as mail
merge is concerned, it doesn't matter how many there are. It
simply loops for as many projects as an employee has; you
don't make the copies, mail merge does.

So, assuming we are both understanding that point correctly,
the only way I can interpret your problem is that you need
to limit the number of projects in the data source, itself?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun
8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)
Monika Krug - 15 Nov 2004 11:10 GMT
Cindy wrote:

>If the data is
>set up so that it simply lists the projects, as far as mail
>merge is concerned, it doesn't matter how many there are. It
>simply loops for as many projects as an employee has; you
>don't make the copies, mail merge does.

You are wrong on that. Read http://support.microsoft.com/?
kbid=105888 very closely and/or try it yourself. It does
not loop for as many projects as an employee has. The
person, not mail merge, has to make as many copies of the
conditional statement as is the maximum number of projects
per employee.

Regards,
Monika.
Doug Robbins - 16 Nov 2004 01:21 GMT
The only other way is to use a macro.

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

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Cindy wrote:
>
[quoted text clipped - 15 lines]
> Regards,
> Monika.
Cindy M  -WordMVP- - 16 Nov 2004 17:15 GMT
Hi Monika,

Been a long time since I read the article... I see what
you're talking about, BUT you should be able to set it up the
way I described. I've done it before, and so have others
(which is why it's been so long since I've read the article.

1. You don't need an extra column for "checked". You can test
the equivalent of "Employee".

2. You don't need NextIf, either.

Take a look at the following set of fields plus text. The ¶
is a paragraph mark (where you press ENTER). We start by
checking whether this is the first record, and if it is,
display the introductory text. Then we set the primary test
for the value on which the records are sorted. We do the
comparison, insert the text, then set the second test. As
each merge record cycles, the new value is checked against
the old value. Notice, too, which the static text is present
in both "true" and "false" conditions.

{ If { MERGEREC } = 1 "Employee: { MERGEFIELD "EmployeeID" }¶
" }{ Set test { MERGEFIELD "EmployeeID" } }¶
{ IF { Ref test } = { Ref testchange } "Item: { MERGEFIELD
"ProductName" }" "¶Closing text ---Page Break---
Employee: { MERGEFIELD "EmployeeID" }¶

Item: { MERGEFIELD "ProductName" }" }{ Set testchange {
MERGEFIELD "EmployeeID" } }

> >If the data is
> >set up so that it simply lists the projects, as far as
[quoted text clipped - 7 lines]
> kbid=105888 very closely and/or try it yourself. It does
> not loop for as many projects as an employee has.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun
8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.