Help with IIf statement

Fisher

Registered User.
Local time
Today, 03:19
Joined
Dec 17, 2003
Messages
28
Hello,
I'm having trouble trying to adjust a report in which I use IIf statements.
I have a database that tracks all the major joint replacement surgeries done. (Total hip replacment, total knee replacement, etc.) In my report, the various surgeries are total for a defined time period which is determined through a calendar control on a form.

=Sum(IIf([Surgery]="Total Hip Replacement" And [AdmDate] Between [Forms]![DateRangeMonthlyRehabfrm]![DateRangeCalendar1] And [Forms]![DateRangeMonthlyRehabfrm]![DateRangeCalendar2],1))

My problem is that we have now separated out the revision surgeries, (Total hip revision, etc.), but i still want to total them together. I have searched here on nested IIF statements but, I can't seem to get it right. I want a total number of all surgeries that are "Total Hip Replacement" OR "Total Hip Revision" and the admit date (AdmDate) is within the selected date range.

Any help would be greatly appreciated.
 
When you build complex conditions that include combinations of AND, OR, and NOT, you need to be very careful to use parentheses so that your conditions are evaluated as you intend. It sounds like you want:

(A or B) And C

rather than

A or (B And C) -- which is how the condition will be evaluated based on the rules of precedence. AND's are evaluated before OR's. But placing parentheses around a condition will cause it to be evaluated before other conditions.
 
Thanks very much Pat. I seem to be always trying to make things too difficult. I struggled a lot with it. When you pointed out the And before Or rule (which I did not know) it became very clear.
Thanks again.
 
I should have pointed out that this is not an Access rule. It is part of boolean logic and will be true in whatever computer language you use and also in SQL. Algebra has similar precedence rules which cause A + B * C to be evaluated as A + (B * C) which is not = (A + B) * C
 

Users who are viewing this thread

Back
Top Bottom