Results 1 to 11 of 11
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Help With Field (2003)

    Hi,

    I am trying to create an IF Field to test 2 conditions. I have tried various combinations with various degrees of failure - from getting the same result regardless of the data, to syntax, field calculation and other errors.

    I want to test a MergeField called TestsTaken to see if it =2 AND a MergeField called Test2 to see if the score is <70. If both are satisfied, I want to print a message STARTING WITH A NEW LINE CHARACTER; if either is false, do nothing. So I put the Field at the end of a line, just before the existing paragraph mark, so that I get the message on a new line only if both conditions are satisfied; otherwise, nothing gets printed.

    The first thing I need help with is how to specify a new line as part of the True text.

    More importantly, how do I create the IF test? I have tried various combinations for the condition - using the AND field or multiplying the 2 conditions by each other (which I started with but switched to AND in desparation).

    My latest attempt is as follows (where { } are entered in Word as CTRL+F9)
    { IF { =AND( { MERGEFIELD TestsTaken} = 2, {MERGEFIELD Test2} < 70) } "message starting with new line" ""}

    I've tried various combinations of putting my field names in quotes or not, spacing, etc.

    TIA

    Fred

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Help With Field (2003)

    Hi All,

    I've solved the problem of the multiple tests by using nested IFs. I would have preferred to do it differently since nested IFs can be hard to read. So if you have a different solution (using AND or multiplying the 2 conditions together), pls let me know.

    Still have NOT figured out how to start my message with a new line.

    Thks.

    Fred

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Help With Field (2003)

    > Still have NOT figured out how to start my message with a new line.

    You should be able to just start a new line inside the """" characters for the True part of the If result.

    StuartR

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Help With Field (2003)

    Hi Stuart,

    I'll bite - how?

    If I was writing something in VBA, I'd do something like vbCRLF & "message so that the message would start a new line.

    I tried a few things like "^pmessage" where ^p is what Find/Replace uses for a new line. Didn't work.

    Fred

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Help With Field (2003)

    Sorry, this is SO simple that I forgot to explain. You literally put a newline in between the quotes, using the enter key. This won't show up as a newline when you update the field, unless the condition tests as true...

    { If {MERGEFIELD Test2} < 70, "
    this text will appear on a newline if the condition is true" "this text will appear without a new line if the condition is false" }

    You can put quite complex things inside those quotes, including for example tables with embedded graphics.

    StuartR

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Help With Field (2003)

    Duh - who would have ever thought?

    Too simple!

    Thanks Stuart.

    Fred

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Help With Field (2003)

    Hi Fred,

    For an effective AND test, you could use:
    {IF{=({MERGEFIELD TestsTaken}= 2)*({MERGEFIELD Test2}< 70)}> 0 "message starting with new line" ""}
    The advantage this has over using Word's AND function is that you can test more than two conditions at a time.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Help With Field (2003)

    Hi Macropod,

    Thanks for the field. I had looked at your Math Calcs posting and still could not get the syntax quite right. Don't recall what I was doing that was wrong so I resorted to using Nested IFs. I'll give this a go because I prefer this kind of structure over nested IFs and AND fields (I use array formulas in Excel alot and your structure is more like that).

    Originally one of my fields was going to be one that had text results. I recall some limitation in using one of the approaches (Nested IFs, AND, or multiplication) with such a field. How would the answer change if that was the case?

    Fred

  9. #9
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Help With Field (2003)

    Hi Fred,

    I'm not sure I understand - the solution I posted is for generating text results. You can combine as many AND (*) and OR (+) expressions as you like this way. The limitations you might be thinking of concern Word's AND and OR field functions, which are limited to just two conditions each.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  10. #10
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Help With Field (2003)

    Hi Macropod,

    I recall from your Math Field Calc posting that there were two limitations for AND: the number of tests and, quoting from V1.11 of your document:

    Word

  11. #11
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Help With Field (2003)

    Hi Fred,

    I suggest you download the latest edition of my Word Field maths 'tutorial' - now at version 1.25. See <post#=365442>post 365442</post#>. It has quite a bit more on string testing, including logical AND, and OR tests.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •