View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Mike[_8_] Mike[_8_] is offline
external usenet poster
 
Posts: 3
Default Grouping Nested If Statements

On Sep 5, 3:55 pm, "macropod" wrote:
Hi mbrinson,

While you're pondering the Directory (Catalog) merge, here's a bit more to chew on.

For the conditions you posted, the following field construction should do the job:
{If{MERGEFIELD Date1} "" {IF{MERGEFIELD Date2} "" {IF{MERGEFIELD Date3} "" "Paragraph 3" "Paragraph 2"} "Paragraph 1"} ""}

But are you sure you haven't overlooked 5 other possibilities:
If Date1 = "" and Date2 = "" and Date3 = "" then EVAL = ?
If Date1 "" and Date2 = "" and Date3 "" then EVAL = ?
If Date1 = "" and Date2 = "" and Date3 "" then EVAL = ?
If Date1 = "" and Date2 "" and Date3 = "" then EVAL = ?
If Date1 = "" and Date2 "" and Date3 "" then EVAL = ?

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

wrote in oglegroups.com...
I'm trying to create a conditional form letter that is conditional on
whether or not a field has data.
The desired output is three blocks of text fit onto one page based on
whether or not there is date information for the fields "Date1",
"Date2", or "Date3"


I can get it to work fine if I don't care about leaving blank space on
a page. So, if there is only data for Date1, then it will fill in the
text for the first paragraph and then leave the rest of the page blank
and then move on to the next record on the next page. I'm trying to
save that space and make it move to the next record and place the next
text block immediately after the last one instead of leaving the rest
of the page blank for that record.


So, here's the core of the logic:


I have an if statement that evaluates for three conditions.
If Date1 "" and Date2 = "" and Date3 = "" then EVAL = 1
If Date1 "" and Date2 "" and Date3 = "" then EVAL = 2
If Date1 "" and Date2 "" and Date3 "" then EVAL = 3


Then at the end of each conditional insertion of the text block I set
P1 or P2 or P3 equal to a value that corresponds with the DateX that
has been inserted (1, 2, or 3)


P1 is Paragraph 1 on the page.
P2 is Paragraph 2 on the page.
P3 is Paragraph 3 on the page.


P1 = 1 when Paragraph 1 has been filled with the text block
corresponding to Date1 not being blank.
P1 = 2 when Paragraph 1 has been filled with the text block
corresponding to Date2 not being blank.
P1 = 3 when Paragraph 1 has been filled with the text block
corresponding to Date3 not being blank.


P2 = 1 when Paragraph 1 has been filled with the text block
corresponding to Date1 not being blank.
etc..... through P3 = 3.


This, coupled with the value for EVAL provides me with a basis to
determine where exactly each text block has been placed and so know
when the last date has been processed (if there's only 1 then EVAL =
1, if there are 2, EVAL = 2, etc...) for that record. This is
necessary so that the merge document knows when to go to the next
record based on a NextIF { REF go } = 1.


I have all of the logic worked out for the case of EVAL = 1, EVAL = 2,
EVAL = 3 coupled with the different possibilities of combinations of
P1 - P3 values.


In between each of the Paragraph selection blocks there is where I
need to be able to say "NEXTIF {REF go} = 1"


ONE PAGE (MAIN MERGE DOCUMENT)
++++++++++++++++++++++++++++++++
+P1------------------------------------------------------ +
+ - Block of text1 IF Date1 "" - +
+ ------------------------------------------------------ +
+ - Block of text2 IF Date2 "" - +
+ ------------------------------------------------------ +
+ - Block of text3 IF Date3 "" - +
+ ------------------------------------------------------ +
+==============================+
+P2------------------------------------------------------ +
+ - Block of text1 IF Date1 "" - +
+ ------------------------------------------------------ +
+ - Block of text2 IF Date2 "" - +
+ ------------------------------------------------------ +
+ - Block of text3 IF Date3 "" - +
+ ------------------------------------------------------ +
+==============================+
+P3------------------------------------------------------ +
+ - Block of text1 IF Date1 "" - +
+ ------------------------------------------------------ +
+ - Block of text2 IF Date2 "" - +
+ ------------------------------------------------------ +
+ - Block of text3 IF Date3 "" - +
+ ------------------------------------------------------ +
++++++++++++++++++++++++++++++++


So, if anyone is still with me at this point, here is my problem:


The logic to figure this out requires grouping nested IF statements.
Here's how it would be in pseudo code:


For the Case of EVAL = 1
IF eval = 1
THEN IF p1 = 1 OR p2 = 1 OR P3 = 1
THEN go = 1
ELSE go = 0
END IF


For the Case of EVAL = 2 (pX would never be equal to 3 because date3
would be empty in this (eval = 2) case)
IF eval = 2
THEN IF ((p1 = 1 OR p1 = 2) AND (p2 = 1 OR p2 = 2)) OR ((p3 = 1 OR
p3 = 2) AND (p1 = 1 OR p1 = 2)) OR ((p2 = 1 OR p2 = 2) AND (p3 = 1 OR
p3 = 2))
THEN go = 1
ELSE go = 0
END IF


For the Case of EVAL = 3
IF eval = 3
THEN IF (p1 = 1 OR p1 = 2 OR P1 = 3) AND (p2 = 1 OR p2 = 2 OR p2 =
3) AND (p3 = 1 OR p3 = 2 OR P3 = 3)
THEN go = 1
ELSE go = 0


I've put this into the nested IF structure for the {IF expression ""
""} structure based on if it's AND then I put the new nested IF in the
first set of parenthesis, and if it's OR then in the second set of
parenthesis. BUT IT DOESN'T WORK.


Any help or ideas for this? Sorry about the long drawn out
explanation. I hope I've got the logic figured out. I've been
banging my head on this one a while.


THANKS!


Sorry, forgot to mention that just because of the business logic there
will always be a date1. If there is a date2 then there is a date1.
Also if there is a date3, then there is a date2.
Thanks for the IF statement construction. I'm going to try that out
just to see now anyway.
Thanks so much for taking the time to respond. You guys are great!