Error returned

  • Thread starter Thread starter Deltic
  • Start date Start date
D

Deltic

I am using the following two pieces of code unfortunatly both return
error# rather than the results i was expecting, can anyone see where i
may be going wrong?

colour: IIf([HRSDown]="0","YES (Green)",IIf([HRSDown]>"0" And
[HRSDown]<="3","Yes (Amber)","No Red"))

hoursdowntext: IIf([HRSDown]="0","On Programme")
 
Try this id your HRSDown field is a number field instead of text --
colour: IIf([HRSDown]=0,"YES (Green)",IIf([HRSDown]>0 And
[HRSDown]<=3,"Yes (Amber)","No Red"))

hoursdowntext: IIf([HRSDown]=0,"On Programme")
 
Try this id your HRSDown field is a number field instead of text --
colour: IIf([HRSDown]=0,"YES (Green)",IIf([HRSDown]>0 And
[HRSDown]<=3,"Yes (Amber)","No Red"))

hoursdowntext: IIf([HRSDown]=0,"On Programme")

--
KARL DEWEY
Build a little - Test a little



Deltic said:
I am using the following two pieces of code unfortunatly both return
error# rather than the results i was expecting, can anyone see where i
may be going wrong?
colour: IIf([HRSDown]="0","YES (Green)",IIf([HRSDown]>"0" And
[HRSDown]<="3","Yes (Amber)","No Red"))
hoursdowntext: IIf([HRSDown]="0","On Programme")- Hide quoted text -

- Show quoted text -

Thanks that worked a treat looks like i had too many quotation marks.
 
Another method you might want to consider would be the Switch( ) function.
Its syntax would be:

Colour:Switch([HRDDown]=0, "Yes (Green)", [HRSDown] <=3, "Yes (Amber)",
True, "No (Red)")

Basically, the difference between the IIF( ) function and Switch( ) function
is that IIF operates like:

IF [HRSDown] = 0 Then
colour = "Yes (Green)"
Else
IF [HRSDown] > 0 and [HRSDown] <= 3 Then
colour = "Yes (Amber)"
Else
colour = "No (Red)"
endif
endif

Where the Switch function operates like:


IF [HRSDown] <= 0 Then
colour = "Yes (Green)"
ElseIF [HRSDown] <= 3 Then
colour = "Yes (Amber)"
Else
colour = "No (Red)"
endif

The advantage of this is that value of the first expression that evaluates
to true will be returned. Additionally, if you test for [HRSDown] <= 0 in
the first expression, you don't have to check for [HRSDown] >0 in the second
expression, because by default we know that it is > zero (or the first
expression would have been selected).

The other benefit of SWITCH is that nested IIF statements get really
difficult to read, and they actually evaluate all of the expressions in the
statment, even if the first expression evaluates to True.

HTH
Dale
 
Back
Top