IF statement not working

  • Thread starter Thread starter CPelkey
  • Start date Start date
C

CPelkey

I have a form where the user enters the number of reports for the current
year as well as the number of reports for the previous year. I want to use
this information to automatically tell the user whether the number of reports
has increased or decreased.

REPTotal is the total reports for the current year
PrevYearREP is the number of reports for the previous year.

Here is the IF statement I am using:

{ IF (REPTotal>PrevYearREP "an increase" "a decrease") }

I don't anticipate the numbers ever being the same. For some reason, no
matter what numbers I use, the field ALWAYS displays "an increase". The field
is not locked, and I have been updating it after changing the numbers.

What am I doing wrong?
 
Assuming that REPTotal and PrevYearREP are global variables or bookmarks,
they must be inserted as REF fields in your code:

{ IF { REPTotal } > { PrevYearREP } "an increase" "a decrease" }

Also, note that each pair of field delimiters, { }, must be added by
pressing Ctrl+F9.
 
Stefan, thanks for your reply!

I tried inserting the references using Ctrl+F9, but now instead of giving a
result, it comes back with the contents of the first reference. So whatever
number is in REPTotal displays in the field instead of either of the text
values =(

Is there anything else you can think of?
 
How did you create the starting and closing braces? These must also be
inserted via Ctrl+F9 (or via the Field dialog box of course); otherwise you
haven't got a working IF field construct.
 
Yes, I am using Ctrl+F9 to enter all fields. I have several fields in the
document that all work perfectly well, but none of the If-Then-Else
statements I use seem to work. There must be some kind of syntax error I am
making, I just don't have the experience to be able to find it.
 
Hi CPelkey,

Instead of an IF test, try something along the lines of:
{={ REPTotal }-{ PrevYearREP } \# "'an increase';'a decrease';'no change'"}

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.
 
macropod,

Thank you sooooooo much, it works perfectly now!!

macropod said:
Hi CPelkey,

Instead of an IF test, try something along the lines of:
{={ REPTotal }-{ PrevYearREP } \# "'an increase';'a decrease';'no change'"}

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.

--
Cheers
macropod
[Microsoft MVP - Word]


CPelkey said:
I have a form where the user enters the number of reports for the current
year as well as the number of reports for the previous year. I want to use
this information to automatically tell the user whether the number of reports
has increased or decreased.

REPTotal is the total reports for the current year
PrevYearREP is the number of reports for the previous year.

Here is the IF statement I am using:

{ IF (REPTotal>PrevYearREP "an increase" "a decrease") }

I don't anticipate the numbers ever being the same. For some reason, no
matter what numbers I use, the field ALWAYS displays "an increase". The field
is not locked, and I have been updating it after changing the numbers.

What am I doing wrong?

.
 
Clever!

--
Stefan Blom
Microsoft Word MVP



macropod said:
Hi CPelkey,

Instead of an IF test, try something along the lines of:
{={ REPTotal }-{ PrevYearREP } \# "'an increase';'a decrease';'no
change'"}

Note: The field brace pairs (ie '{ }') for the above example are created
via Ctrl-F9 - you can't simply type them or copy & paste them from this
message.

--
Cheers
macropod
[Microsoft MVP - Word]


CPelkey said:
I have a form where the user enters the number of reports for the current
year as well as the number of reports for the previous year. I want to
use
this information to automatically tell the user whether the number of
reports
has increased or decreased.

REPTotal is the total reports for the current year
PrevYearREP is the number of reports for the previous year.

Here is the IF statement I am using:

{ IF (REPTotal>PrevYearREP "an increase" "a decrease") }

I don't anticipate the numbers ever being the same. For some reason, no
matter what numbers I use, the field ALWAYS displays "an increase". The
field
is not locked, and I have been updating it after changing the numbers.

What am I doing wrong?
 
Back
Top