I get an error message "expression is too complex" when i do this:
After52:
[CustExp2]+Switch(Hour([TimeAssigned])=18,1,Hour([TimeAssigned])=19,2,Hour([TimeAssigned])=20,3,Hour([TimeAssigned])=21,4,Hour([TimeAssigned])=22,5,Hour([TimeAssigned])=23,6,Hour([TimeAssigned])=0,-8,Hour([TimeAssigned])=1,-7,Hour([TimeAssigned])=2,-6,Hour([TimeAssigned])=3,-5,Hour([TimeAssigned])=4,-4,Hour([TimeAssigned])=5,-3,Hour([TimeAssigned])=6,-2,Hour([TimeAssigned])=7,-1,Hour([TimeAssigned])=8,0)
and also when I do this:
After52:
[CustExp2]+Switch(Hour([TimeAssigned])=18,1,Hour([TimeAssigned])=19,2,Hour([TimeAssigned])=20,3,Hour([TimeAssigned])=21,4,Hour([TimeAssigned])=22,5,Hour([TimeAssigned])=23,6,Hour([TimeAssigned])=0,-8,Hour([TimeAssigned])=1,-7,Hour([TimeAssigned])=2,-6,Hour([TimeAssigned])=3,-5,Hour([TimeAssigned])=4,-4,Hour([TimeAssigned])=5,-3,Hour([TimeAssigned])=6,-2,Hour([TimeAssigned])=7,-1,Hour(([TimeAssigned])>=8
and [TimeAssigned]<=17),0)
John W. Vinson said:
I'm building the following expression:
after5: IIf([TimeAssigned] Like "6:*PM",[CustExp2]+1,(IIf([TimeAssigned]
Like "7:*PM",[CustExp2]+2,(IIf([TimeAssigned] Like
"8:*PM",[CustExp2]+3,(IIf([TimeAssigned] Like
"9:*PM",[CustExp2]+4,(IIf([TimeAssigned] Like
"10:*PM",[CustExp2]+5,(IIf([TimeAssigned] Like
"11:*PM",[CustExp2]+6,(IIf([TimeAssigned] Like
"12:*AM",[CustExp2]-8,(IIf([TimeAssigned] Like
"1:*AM",[CustExp2]-7,(IIf([TimeAssigned] Like
"2:*AM",[CustExp2]-6,[CustExp2])))))))))))))))))
When I continue to add the 3am, 4am, etc. I get an error message that
says
it is too complex. What does that mean? How can I fix it?
Two suggestions: one would be to use Switch() rather than nested IIF; and
the
other - a bit more work but much simpler and more flexible in the long
run -
is to use a table.
Switch() takes arguments in pairs; evaluates the pairs left to right; and
returns the second member of the first pair encountered for which the
first
element is True. You can also make some considerable simplification by
not
repeating CustExp2 in every choice, and treating the time as a datetime
value
rather than as a string (if it IS a string you can use CDate() to convert
it
to a date/time):
After5: [CustExp2] + Switch(Hour([TimeAssigned])=18, 1,
Hour([TimeAssigned])=19, 2,
Hour([TimeAssigned[) = 20, 3,
<etc>
Or, to allow more flexibility (e.g. half-hour increments) create a three
field
table TimeFactors with StartTime, EndTime, and Factor:
#06:00PM# #07:00PM# 1
#07:00PM# #08:00PM# 2
etc.
Join this to your table using a "non equi join":
SELECT <other fields>, [Factor] * [CustExp2]
FROM yourtable INNER JOIN TimeFactors
ON yourtable.[TimeAssigned] >= Timefactors.StartTime
AND yourtable.[TimeAssigned] < Timefactors.EndTime
John W. Vinson [MVP]