multipule iif

tubar

Registered User.
Local time
Today, 10:56
Joined
Jul 13, 2006
Messages
190
I cant get this statement to show 0 at the end of the day...sorry im new and lack terms

Ms1: IIf([accum] Between 10.5 And 24,IIf([nomeal]=0 And [meal2]=0,"2",IIf([nomeal]=-1 And [meal2]=0,"1",IIf([nomeal]=0 And [meal2]=-1,"2","0"))))

i have tried the end 0 with and without""
 
When you get that nested with IIF statements its time to make a function so that us mere humans know whats going on.

That means in the query you put this where you have that monstrosity:

MS1: YourFunctionNameHere(accum, nomeal, meal2)

Then you create a function in a module. You can paste this in:

Code:
Function YourFunctionNameHere(a, n, m)
    ' a is accum field value, n is nomeal value, m is meal2 value
ret = 0
If a >= 10.5 And a <= 24 Then
    If n = 0 And m = 0 Then ret = 2
    If n = 0 And m = -1 Then ret = 2
    If n = -1 And m = 0 Then ret = 1
    End If
 
YourFunctionNameHere = ret
End Function

Now, I may have gotten confused along the way trying to decipher that code you had, so let me explain what my code does and you tell me if its right or wrong.

By default it is 0.
If accum is between 10.5 and 24 then it looks at nomeal and meal 2 and does this
--if nomeal and meal2 are both 0 it returns 2
--if no meal is -1 and meal2 is 0 it returns 1
--if no meal is 0 and meal2 is -1 it returns 2
--if none of the above conditions are met it doesn't change the default and returns 0
 

Users who are viewing this thread

Back
Top Bottom