none
Microsoft Word IF Fields problem RRS feed

  • Question

  • Windows 7 Enterprise SP 1
    Microsoft Word Version 14.0.5128.5000 (32-bit)

    Certain usage of IF-Fields will cause word to refuse to update them, saying they are nested too deeply. Word's defined field-nesting limit is a maximum of 20, but these IF-fields are not nested beyond two levels. More so, they actually have less than 20 total fields inside them.

    Simply, if you have one IF-Field, and inside of it you have 18-19 IF-fields one after another (not nested), it will cause word to declare that they are nested too deeply and will not update them.

    I have also observed strange issues where having 17 IF-fields together inside another IF-field does not cause word to refuse to update them, but adding another IF field immediately after the outer IF-field will cause that outer IF-field to start refusing to update. I was unable to recreate this exact issue in the example document, but it is somewhat reflected in that the last two IF fields are exactly the same (copied & pasted) with a total of 19 IF-fields. The first one refuses to update but the second one does not.

    Note that these issues appear to only occur for IF-fields, not for the others I tested (which were ASK and FILLIN fields).

    Friday, May 13, 2011 7:55 PM

Answers

  • If there's a bug, it probably has to do with the wrong error message being generated, rather than anything to do with Word not honouring the field nesting limit. In the case you posted, it should return the 'field too complex'' error message. Nevertheless, I'm more concerned with finding a solution than cogitating over whether it's a field bug or what the right error message should be.

    With the first version of your field, updating does occur up to 20 nested levels, without the addition of REF fields, as can be demonstrated via:

    {QUOTE{ASK Val}{IF Val = 1 "One" {IF Val = 2 "Two" {IF Val = 3 "Three" {IF Val = 4 "Four" {IF Val = 5 "Five" {IF Val = 6 "Six" {IF Val = 7 "Seven" {IF Val = 8 "Eight" {IF Val = 9 "Nine" {IF Val = 10 "Ten" {IF Val = 11 "Eleven" {IF Val = 12 "Twelve" {IF Val = 13 "Thirteen" {IF Val = 14 "Fourteen" {IF Val = 15 "Fifteen" {IF Val = 16 "Sixteen" {IF Val = 17 "Seventeen" {IF Val = 18 "Eighteen" {IF Val = 19 "Nineteen" {IF Val = 20 "Twenty" "Twenty-One"}}}}}}}}}}}}}}}}}}}}}

    I should also point out that such nesting is completely unnecessary in this case, witness:

    {QUOTE{IF 100 = 1 "One" {IF 100 = 2 "Two" {IF 100 = 3 "Three" {IF 100 = 4 "Four" {IF 100 = 5 "Five" {IF 100 = 6 "Six" {IF 100 = 7 "Seven" {IF 100 = 8 "Eight" {IF 100 = 9 "Nine" {IF 100 = 10 "Ten"}}}}}}}}}}{IF 100 = 11 "Eleven" {IF 100 = 12 "Twelve" {IF 100 = 13 "Thirteen" {IF 100 = 14 "Fourteen" {IF 100 = 15 "Fifteen" {IF 100 = 16 "Sixteen" {IF 100 = 17 "Seventeen" {IF 100 = 18 "Eighteen" {IF 100 = 19 "Nineteen" {IF 100 = 20 "Twenty"}}}}}}}}}}{IF 100 = 21 "Twenty-one" {IF 100 = 22 "Twenty-two" {IF 100 = 23 "Twenty-three" {IF 100 = 24 "Twenty-four" {IF 100 = 25 "Twenty-five" "FOO BAR!"}}}}}}

    If you have a real-world example you're having trouble with, post it and I'll have a go at providing a solution.

     


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by Bob Tervin Wednesday, May 18, 2011 4:27 PM
    Wednesday, May 18, 2011 4:04 AM

All replies

  • Hi rtervin,

    I suspect the issue is to do with how you have encoded your fields. If you check out my Microsoft Word Date Calculation Tutorial, at:
    http://lounge.windowssecrets.com/index.php?showtopic=249902 and http://www.gmayor.com/downloads.htm#Third_party
    or my Microsoft Word Field Maths Tutorial, at:
    http://lounge.windowssecrets.com/index.php?showtopic=365442 and http://www.gmayor.com/downloads.htm#Third_party
    you'll see that nested fields can be quite complex, though I tend not to nest IF fields a great deal (6 or 7 is about the maximum I've ever needed) - usually there are better approaches.

    If you care to describe in detail what you're trying to achieve, I might be ble to suggest a better approach. It would also help if you could post your field code. There are macros for converting between true fields and text representations of them at:
    To Text - http://www.gmayor.com/export_field.htm#FieldToText
    From Text: http://www.gmayor.com/export_field.htm#TextToField

    FWIW, the actual nesting limit is somewhat greater than 20 (in Word 2007). The following has 32! nested IFs and it still works:

    {QUOTE{ASK Val}{IF Val = Val {Val} {IF Val = 2 {Val} {IF Val = 3 {Val} {IF Val = 4 {Val} {IF Val = 5 {Val} {IF Val = 6 {Val} {IF Val = 7 {Val} {IF Val = 8 {Val} {IF Val = 9 {Val} {IF Val = 10{Val} {IF Val = 11 {Val} {IF Val = 12 {Val} {IF Val = 13 {Val} {IF Val = 14 {Val} {IF Val = 15 {Val} {IF Val = 16 {Val} {IF Val = 17 {Val} {IF Val = 18 {Val} {IF Val = 19 {Val} {IF Val = 20 {Val} {IF Val = 21 {Val} {IF Val = 22 {Val} {IF Val = 23 {Val} {IF Val = 24 {Val} {IF Val = 25 {Val} {IF Val = 26 {Val} {IF Val = 27 {Val} {IF Val = 28 {Val} {IF Val = 29 {Val} {IF Val = 30 {Val} {IF Val = 31 {Val} {IF Val = 32 {Val} 33}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Friday, May 13, 2011 9:42 PM
  • Here is an example of the problem:

    This IF-field refuses to update, because the maximum number of IF fields it has to process is 19 
    (6 Left side of comparison + 6 Right side of comparison + 6 max IF fields in either true/false result + 1 outer IF field):
    { IF "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" 
    = "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" 
    "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" 
    "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" }
    
    This IF-field will update, because the maximum number of IF fields it has to process is 18
    (5 Left side of comparison + 6 Right side of comparison + 6 max IF fields in either true/false result + 1 outer IF field):
    { IF "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" 
    = "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" 
    "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" 
    "{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }{ IF "A" = "A" "B" }" }
    

    This is not so much what we are trying to do as it is trying to figure out what limitations we may have to enforce to prevent our users from having problems due to this issue.

    Monday, May 16, 2011 1:30 PM
  • Hi rtervin,

    You can overcome that particular problem fairly simply:

    {SET AA {IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}}
    {SET BB {IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}}
    {SET AB {IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}}
    {SET BA {IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}}
    {IF AA = BB AB BA}

    The above would be suitable for a mailmerge or for use with formfields. Alternatively, to keep all the fields within the same expression so they can be guaranteed to update together:

    {IF{={IF "A" = "A" 1 0}+{IF "A" = "A" 2 0}+{IF "A" = "A" 4 0}+{IF "A" = "A" 8 0}+{IF "A" = "A" 16 0}+{IF "A" = "A" 32 0}} = {={IF "A" = "A" 1 0}+{IF "A" = "A" 2 0}+{IF "A" = "A" 4 0}+{IF "A" = "A" 8 0}+{IF "A" = "A" 16 0}+{IF "A" = "A" 32 0}} "{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}" "{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}{IF "A" = "A" "B"}"}


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Monday, May 16, 2011 10:08 PM

  • That is definitely a useful practice we hadn't considered, and should be a handy workaround.

    However, I still believe the original issue is an outright bug, because it is mistakenly applying the 20-nested-field limit to IF fields in situations that do not come anywhere close to that limit. Additionally, it does not appear to affect other types of fields; only IF fields. This is a problem for us because we do not have complete control over what OUR users put in their word documents, so they could design groups of fields that look fine, but trigger this bug.

     

    Regarding your original post, It seems that having 'REF' fields in the nested IF-fields is not triggering the 20-nested limit. Removing those 'REF' fields and replacing with static numbers DOES trigger the 20-nested limit.

    This IF field refuses to update:

    { IF 100 = 1 "One" { IF 100 = 2 "Two" { IF 100 = 3 "Three" { IF 100 = 4 "Four" { IF 100 = 5 "Five" 
     { IF 100 = 6 "Six" { IF 100 = 7 "Seven" { IF 100 = 8 "Eight" { IF 100 = 9 "Nine" { IF 100 = 10 "Ten" 
     { IF 100 = 11 "Eleven" { IF 100 = 12 "Twelve" { IF 100 = 13 "Thirteen" { IF 100 = 14 "Fourteen" { IF 100 = 15 "Fifteen" 
      { IF 100 = 16 "Sixteen" { IF 100 = 17 "Seventeen" { IF 100 = 18 "Eighteen" { IF 100 = 19 "Nineteen" { IF 100 = 20 "Twenty" 
      { IF 100 = 21 "Twenty-one" { IF 100 = 22 "Twenty-two" { IF 100 = 23 "Twenty-three" 
       { IF 100 = 24 "Twenty-four" { IF 100 = 25 "Twenty-five" "FOO BAR!" } 
    } } } } } } } } } } } } } } } } } } } } } } } }

     

    If I replace each instance of "100" with "{ REF Val }", and Val = 100 (a previous ASK field in the document set that), then this field updates and shows "FOO BAR!":

    { IF { REF Val } = 1 "One" { IF { REF Val } = 2 "Two" { IF { REF Val } = 3 "Three" { IF { REF Val } = 4 "Four" { IF { REF Val } = 5 "Five" 
     { IF { REF Val } = 6 "Six" { IF { REF Val } = 7 "Seven" { IF { REF Val } = 8 "Eight" { IF { REF Val } = 9 "Nine" { IF { REF Val } = 10 "Ten" 
     { IF { REF Val } = 11 "Eleven" { IF { REF Val } = 12 "Twelve" { IF { REF Val } = 13 "Thirteen" { IF { REF Val } = 14 "Fourteen" { IF { REF Val } = 15 "Fifteen" 
      { IF { REF Val } = 16 "Sixteen" { IF { REF Val } = 17 "Seventeen" { IF { REF Val } = 18 "Eighteen" { IF { REF Val } = 19 "Nineteen" { IF { REF Val } = 20 "Twenty" 
      { IF { REF Val } = 21 "Twenty-one" { IF { REF Val } = 22 "Twenty-two" { IF { REF Val } = 23 "Twenty-three" 
       { IF { REF Val } = 24 "Twenty-four" { IF { REF Val } = 25 "Twenty-five" "FOO BAR!" } 
    } } } } } } } } } } } } } } } } } } } } } } } }
    
     

    Tuesday, May 17, 2011 2:41 PM
  • If there's a bug, it probably has to do with the wrong error message being generated, rather than anything to do with Word not honouring the field nesting limit. In the case you posted, it should return the 'field too complex'' error message. Nevertheless, I'm more concerned with finding a solution than cogitating over whether it's a field bug or what the right error message should be.

    With the first version of your field, updating does occur up to 20 nested levels, without the addition of REF fields, as can be demonstrated via:

    {QUOTE{ASK Val}{IF Val = 1 "One" {IF Val = 2 "Two" {IF Val = 3 "Three" {IF Val = 4 "Four" {IF Val = 5 "Five" {IF Val = 6 "Six" {IF Val = 7 "Seven" {IF Val = 8 "Eight" {IF Val = 9 "Nine" {IF Val = 10 "Ten" {IF Val = 11 "Eleven" {IF Val = 12 "Twelve" {IF Val = 13 "Thirteen" {IF Val = 14 "Fourteen" {IF Val = 15 "Fifteen" {IF Val = 16 "Sixteen" {IF Val = 17 "Seventeen" {IF Val = 18 "Eighteen" {IF Val = 19 "Nineteen" {IF Val = 20 "Twenty" "Twenty-One"}}}}}}}}}}}}}}}}}}}}}

    I should also point out that such nesting is completely unnecessary in this case, witness:

    {QUOTE{IF 100 = 1 "One" {IF 100 = 2 "Two" {IF 100 = 3 "Three" {IF 100 = 4 "Four" {IF 100 = 5 "Five" {IF 100 = 6 "Six" {IF 100 = 7 "Seven" {IF 100 = 8 "Eight" {IF 100 = 9 "Nine" {IF 100 = 10 "Ten"}}}}}}}}}}{IF 100 = 11 "Eleven" {IF 100 = 12 "Twelve" {IF 100 = 13 "Thirteen" {IF 100 = 14 "Fourteen" {IF 100 = 15 "Fifteen" {IF 100 = 16 "Sixteen" {IF 100 = 17 "Seventeen" {IF 100 = 18 "Eighteen" {IF 100 = 19 "Nineteen" {IF 100 = 20 "Twenty"}}}}}}}}}}{IF 100 = 21 "Twenty-one" {IF 100 = 22 "Twenty-two" {IF 100 = 23 "Twenty-three" {IF 100 = 24 "Twenty-four" {IF 100 = 25 "Twenty-five" "FOO BAR!"}}}}}}

    If you have a real-world example you're having trouble with, post it and I'll have a go at providing a solution.

     


    Cheers
    Paul Edstein
    [MS MVP - Word]
    • Marked as answer by Bob Tervin Wednesday, May 18, 2011 4:27 PM
    Wednesday, May 18, 2011 4:04 AM
  • I agree that such nesting is unnecessary, and your example using 'SET' fields is the best workaround I've seen. Unfortunately we will still have to programmatically prevent our users from creating IF and other fields that refuse to update, as it will cause undesired output (mail merge data not displaying correctly because the parent field refused (silently) to update).

    Thank you for your help, and I'll ask rtervin to accept one of your posts as the answer.

    Wednesday, May 18, 2011 3:05 PM