Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / February 2004

Tip: Looking for answers? Try searching our database.

COMPARE Syntax error debugging assistance - Word 2002

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rtrsr - 19 Feb 2004 02:04 GMT
I've had no problems creating and using simple { IF Expression1 Operator
Expression2 TrueText FalseText } merge codes  but now I've plowed into a
stump.

This time, I want to test TWO conditions.  Here's a diagram of what I'm
trying to do.  I acknowledge it's not rocket science but I can't get it to
lift off the pad.

===============
IF
  "{MERGEFIELD FileCustomField15}" = "FALSE"
      ***and***
  {MERGEFIELD FileCustomField7} <> {MERGEFIELD FileCustomField7}

THEN

  "[... text passage #1]"

ELSE

  "[... text passage #2]"
================

I understand from the Help Screens that the way to do this is via the
COMPARE code.  Well, it isn't working for me.  It's probably a matter of not
putting "quotes" in the right place or otherwise not holding my mouth just
right when I type in the code, but after over two hours of beating on it, I
thought someone out here could give me a few pointers.

Here's what I've got (that doesn't work):

{IF {=AND ({COMPARE "{MERGEFIELD FileCustomField15}" = "FALSE"},
{COMPARE{MERGEFIELD FileCustomField7} <> {MERGEFIELD FileCustomField7} } ) }
= 1 "... text passage #1" "... text passage #2"}

I've followed the style in Word's Help Screen for the COMPARE code --
precisely I think.  But I still get an "Error - Missing Test Condition."
I'm sure the error of my ways will be immediately obvious to one of you.
Can you help?

NOTE:  {MERGEFIELD FileCustomField15} is a "string variable" while
{MERGEFIELD FileCustomField7} and MERGEFIELD FileCustomField7} are both
numerics.

Thanks!

Rick
Peter Jamieson - 19 Feb 2004 06:46 GMT
(Just noting that your second condition comapres something with itself)

YOu can use a nested IF. There's a limit to the number of levels and you
have to duplicate results. But e.g.

{ IF "{ MERGEFIELD FileCustomField15 }" = "FALSE"
"{ IF { MERGEFIELD FileCustomField7 } <> { MERGEFIELD FileCustomField7 }
"[... text passage #1]"
"[... text passage #2]" }" "[... text passage #2]" }

COMPARE returns 1 for a successful comparison, 0 otherwise. So you can AND
the results of two COMPAREs in an { = } field and test the result of that,
e.g.

{ IF { =and({ COMPARE "{ MERGEFIELD FileCustomField15 }" = "FALSE" },
{ COMPARE { MERGEFIELD FileCustomField7 } <> { MERGEFIELD
FileCustomField7 } }) } = 1
"[... text passage #1]"
"[... text passage #2]" }

You should be able to do more complicated and/or logic by nesting further
and(,) and or(,) functions.

Just make sure all the {} are the special field braces you can insert using
ctrl-F9

--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

> I've had no problems creating and using simple { IF Expression1 Operator
> Expression2 TrueText FalseText } merge codes  but now I've plowed into a
[quoted text clipped - 43 lines]
>
> Rick
rtrsr - 19 Feb 2004 16:16 GMT
Ahhh.  So THAT'S how you nest IF statements in this language!  Once again,
Peter, your star burns ever brighter in the firmament!

Many, many thanks!!

Rick

PS  > (Just noting that your second condition compares something with
itself) <
Uh, yeah...  That's what happens when I try to type these commands in as
text.  I got a little carried away with Word's Copy/Paste function.  You're
quite right.  A statement that "X <> X" might work in a Court of Law, but
not in any computer I've seen.  So sorry for the confusion.

> (Just noting that your second condition comapres something with itself)
>
[quoted text clipped - 76 lines]
> >
> > Rick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.