ms-wordword-2010fieldcodes

test for error returned by TOC field code


I am trying to test whether any "figure captions" exist before I create a Table of Figures. I have a line of code that works: {IF {TOC \h \z \c "Figure"} = {TOC \h \z \c "blarghel"} " No table" "Entries exist"} (field codes, of course), where "blarghel" is a deliberate dummy. I thought I used to be able (in Word 2003) to quote the error string returned, which for WORD 2010 would be

{IF {TOC \h \z \c "Figure"} = "No table of figures entries found." " No table" "Entries exist"}

But that always returns the failure condition of the "IF" test. I don't see any "ISERROR" kind of field code, and can't figure out what the TOC field code is actually returning.
Any ideas? (and yes, normally I'd replace the second condition with the field code to return the table of figures :-) )

thanks.

Carl


Solution

  • I think you need an extra paragraph mark before the error message in Word 2010. That may have changed since Word 2003 - I have not checked:

    {IF {TOC \h \z \c "Figure"} = " No table of figures entries found." " No table" "Entries exist"}