IIF statement

  • Thread starter Thread starter V. Roe
  • Start date Start date
V

V. Roe

I am using Access 2000.
In a text box on a report (detail section), I am trying to write an
expression that will return the singular or plural depending upon the
results of a calculation. I believe the problem revolves around the fact
that I am using a text box and "1" is text not a number, but I don't know
how to work around this (I am very new to Access). I need to say if (<= 1,
"hour", "hours"). The below expression works, except results that are <1
returns the word "hours". It's not really a big deal, but I hate not doing
it the right way. Any help would be appreciated. Thanks.
Valerie

=(Sum([Length of Service]/60) & (IIf([Length of Service]/60=1," Hour","
Hours")))
 
A text box is just a place holder. If you put a number in it, the contents
will be a number. If you put text, it will be text. The sum function will
reutrn a number so you can still do a check. If you want less than or equal
to 1 use "<=".

=(Sum([Length of Service]/60) & (IIf([Length of Service]/60<=1,"
Hour","Hours")))

Dont; you also want to include another Sum in the IIF part?

=(Sum([Length of Service]/60) & (IIf(sum([Length of Service]/60)<=1,"
Hour","Hours")))

Kelvin
 
Thanks,
I tried that a million times Friday, it works this morning. I guess in all
my editing I had deleted the second "sum".
Valerie
Kelvin said:
A text box is just a place holder. If you put a number in it, the contents
will be a number. If you put text, it will be text. The sum function will
reutrn a number so you can still do a check. If you want less than or equal
to 1 use "<=".

=(Sum([Length of Service]/60) & (IIf([Length of Service]/60<=1,"
Hour","Hours")))

Dont; you also want to include another Sum in the IIF part?

=(Sum([Length of Service]/60) & (IIf(sum([Length of Service]/60)<=1,"
Hour","Hours")))

Kelvin

V. Roe said:
I am using Access 2000.
In a text box on a report (detail section), I am trying to write an
expression that will return the singular or plural depending upon the
results of a calculation. I believe the problem revolves around the fact
that I am using a text box and "1" is text not a number, but I don't know
how to work around this (I am very new to Access). I need to say if (<= 1,
"hour", "hours"). The below expression works, except results that are <1
returns the word "hours". It's not really a big deal, but I hate not doing
it the right way. Any help would be appreciated. Thanks.
Valerie

=(Sum([Length of Service]/60) & (IIf([Length of Service]/60=1," Hour","
Hours")))
 
Back
Top