View Single Post
  #12   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Help with embedded "If"

Can you try opening the following URL in your browser, right-clicking on the
link and downloading the .doc in there?

http://tips.pjmsn.me.uk/suzanne

This .doc should demonstrate the /first/ solution I suggested (although the
layout probably needs fixing in various ways). If not, can you please
describe what it does not do, apart from the known problem of dealing with
the notes in the last record.

If you would find it easier to correspond by e-mail, please despam my e-mail
(remove KillmapS) and email me.
--
Peter Jamieson
http://tips.pjmsn.me.uk

"Suzanne" wrote in message
news
I tried your last example. It's not working.

The result had the first two names at the top and did not pull everyone
together.

I've been messing with it; at one point I had the names grouped, but
somewhere along the line I messed that up. I'm getting a variety of
results
as I continue to mess with this (error codes, misplaced data, skipped
records).

At this point I'm not even working with the actual form but rather a plain
page test document. I think if I can get the plain page worked out, I can
apply it to the real thing.

Thanks -- Suzanne

I still think the answer is close.

"Peter Jamieson" wrote:

1. I think it's a bit easier to follow the logic if you stick to using
one
local variable (and the pattern I suggested before, where you explicitly
set
LOC to "" in that first record, then test LOC against the value of
MERGEFIELD UICROOM, and set LOC again at the end of the mail merge main
document.

2. Because of the way this technique works, it's easiest to imagine that
the
list of names always comes last. Because you actually want some notes
etc.
after the list of names, when you use this technique, you then have to
put
those notes at the very beginning and eliminate them when MERGESEQ is 1
1.
So your merge then looks something like

{ IF { MERGESEQ } = 1 "{ SET LOC "" }{ SET NOTES "" }" "" }
{ IF "{ LOC }" = "{ MERGEFIELD UICROOM }"
"{ NOTES }
your section 1 fields and table
page or {section break
your section 5 page header and column headers" "" }
merge fields you want in the list of names{ SET LOC { MERGEFIELD
UICROOM }{ SET NOTES "whatever you want in the notes at the end of this
group of recordspage or section break }

3. The trouble with this is that the notes under your last list of names
will never be emitted. But because of the way Word works, I don't think
you
can logically achieve what you need without also ensuring that you know
which the last record in each group is. If you know that, e.g. because
you
mark the last recors in each group, you can do something more like

{ IF { MERGESEQ } = 1 "{ SET LOC "" }" "" }
{ IF "{ LOC }" = "{ MERGEFIELD UICROOM }"
"your section 1 fields and table
page or {section break
your section 5 page header and column headers" "" }
merge fields you want in the list of names{
{ IF { MERGEFIELD LASTRECORDINGROUP } = "Y" "output your note text here"
"" }{ SET LOC { MERGEFIELD UICROOM }

Sorry, it's now rather late here so I may not be thinking straight, but
Ireally think that's what you need to do.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Suzanne" wrote in message
...
Peter,

You're a lifesaver. Look for my post "I almost have the 2-page merge"
in
this thread.

When/if you open my Word doc (it's on my Office Live site:
http://suzleigh.com/MERGE.aspx), it will look a little mangled.
Regardless,
I really think that I may almost have this nailed down.

I was able to get this far by creating a new column in my Excel
worksheet:
"UICROOM" -- UIC & ROOM (this might be helpful for anyone in the future
who
is having the same problem). On plain paper, I get exactly the results
I'm
looking for. I still can't get the results on the actual form.

If you look at the form, you'll also see that I switched the pages to
avoid
having to sift through rows/columns of data to get to the names listing
(the
name listing is now page 1; the detailed form is page 2).

Would love your help (and/or anyone else who might be listening in).

Suz

"Peter Jamieson" wrote:

I was away for a couple of days - if you still need a solution I'll
have
another look.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Suzanne" wrote in message
...
After a full day of hopefully waiting for someone to tell me that
there
is
some method of doing what I need, I'll close this out and get on to
cutting/pasting the data for each record (sigh).

Thanks Peter for your help... Suz

"Suzanne" wrote:

I can't get this working... I've been able to get new record
breaks
after
each UIC, but have yet to see just the list of names on the second
page.

A simplified version of what I'm trying to get to:

First Page: UIC BLDG ROOM (followed by rows/columns of text)
Second Page: All people with the same UIC and Room (everyone in
the
room
will have the same building number but not necessarily the same
UIC)

I can adjust the first page of the form so that one table cell will
contain
UIC, BLDG, ROOM. On the top of the second page, I need a list of
names
for
that UIC+Room.

Without your help (hopefully), I'm still stuck at having to
manually
Alt-Tab
between two document to cut/paste the information on the forms.

Thank you VERY much...

Suz

"Peter Jamieson" wrote:

Hi Suzanne

As Doug mentioned in an earlier thread, it's partly a question of
"where to
put your page break".

whatever you put in the TRUE result of the IF field here...

{ If { ={ COMPARE { LUIC } { MERGEFIELD UIC } }+{ COMPARE {
LROOM }

{ MERGEFIELD ROOM } } } = 2
"{ MERGEFIELD UIC }{ MERGEFIELD ROOM }

" "" }

is going to appear when UIC and ROOM change (so that probably
needs
to
have
a page break at the end - you can insert one in the result text)
and
perhaps
you will also need to repeat some of the fields at the beginning
of
that new
page. i.e. you need something like

{ If { ={ COMPARE { LUIC } { MERGEFIELD UIC } }+{ COMPARE {
LROOM }

{ MERGEFIELD ROOM } } } = 2
"{ MERGEFIELD UIC }{ MERGEFIELD ROOM }
whatever else you want on page 1 followed by
page break (put a real page break in here)
followed by whatever text and fields you need at the top of page
2
" "" }

At the moment, my suggestion assumes that the stuff you have in
"whatever
you want here" will be output for every record. This is because
in
this
kind
of merge, the first record in the group also usually contains the
data
for
the first detail record in the group IYSWIM. What I am not sure
about
in
this case is what you mean by...

The second page is not in a table format. Rows of names are at
the
top of
the page.

Can you provide an example of the kind of layout you need to
achieve?
If you
need to avoid having paragraph marks between each record, you
need
to
eliminate any paragraph marks in the mail merge main document
that
would be
output following any of the records, and that probably also means
that
you
need to insert a page break at the beginning of the "heading
texts",
e.g.

{ If { ={ COMPARE { LUIC } { MERGEFIELD UIC } }+{ COMPARE {
LROOM }

{ MERGEFIELD ROOM } } } = 2
"page break{ MERGEFIELD UIC }{ MERGEFIELD ROOM }
whatever else you want on page 1 followed by
page break (put a real page break in here)
followed by whatever text and fields you need at the top of page
2
" "" }

If you need to eliminate the page break on page 1, try

{ If { ={ COMPARE { LUIC } { MERGEFIELD UIC } }+{ COMPARE {
LROOM }

{ MERGEFIELD ROOM } } } = 2
"{ IF { LUIC } "" "page break" "" }{ MERGEFIELD UIC }{
MERGEFIELD
ROOM }
whatever else you want on page 1 followed by
page break (put a real page break in here)
followed by whatever text and fields you need at the top of page
2
" "" }

NB, you cannot eeliminate the final paragraph mark on a page, but
a
directory merge does not insert that one in the output anyway,
i.e.
if
your
mail merge main document just ha

{ MERGEFIELD UIC }

and nothing else except that final para, your output would have

UIC1UIC2UIC3UIC4...

You may find in practice that this introduces other problems (for
one
thing,
I hope I have the logic the right way around!) but try it anyway.
--
Peter Jamieson
http://tips.pjmsn.me.uk

"Suzanne" wrote in message
...
Thanks! The third one did it (I didn't try the other two).
You
are
correct
in that none of the fields are empty.

I've given up hope on this, but here's one last shot... now
that
the
data
is
in Word, is there anyway to automate my Word form with these
results?
I
was
told I couldn't do it straight from Excel.

I have a two-page form with numerous table columns and rows.
The
UIC,
Building, and Room go on the top of the first page. Names
which
are
associated with that UIC/Bldg/Room combination go on the second
page.

The second page is not in a table format. Rows of names are at
the
top of
the page.

I'm ready to conclude that despite the great things that Word
can
do,
I
may
have to manually align, cut/paste, and validate data on the
form
I'm
required
to use.

Suz

"Peter Jamieson" wrote:

Assuming you're doing a "one-many" type merge
There are at least two problems in your current code:
a. you can't do the AND the way you are trying to do it at
the
moment
b. you seem to be inserting the same thing whether UIC and
ROOM
change
or
not.

If you only want to test for a change in either UIC or ROOM,
you
can
try

{ IF { MERGESEQ } = "1" "{ SET LUIC "" }{ SET LROOM "" }" ""
}{ If "{ LUIC }{ LROOM }" "{ MERGEFIELD UIC }{ MERGEFIELD
ROOM }"
"{ MERGEFIELD UIC }{ MERGEFIELD ROOM }

" "" }whatever you want here
{ SET LUIC { MERGEFIELD UIC } }{ SET LROOM { MERGEFIELD
ROOM } }

or perhaps even just

{ IF { MERGESEQ } = "1" "{ SET UICROOM "" }" ""
}{ If "{ UICROOM }" "{ MERGEFIELD UIC }{ MERGEFIELD ROOM }"
"{ MERGEFIELD UIC }{ MERGEFIELD ROOM }