Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIf Then Syntax to perform Calculation

Status
Not open for further replies.

bethabernathy

Programmer
Jul 13, 2001
254
MX
I am trying to generate a calculation on a report. The database tracks a ski areas lockers revenue and member information. I need to calculate the total deposit amount for the lockers. If the field "PPDepPaid" from the Locker table is equal to "Yes", then the field "ParkingDepositPrice" from the Prices table needs to be totalled in the report.

So in the report footer I am using the following syntax in a text box: "=IIf([PPDepPaid]=-1,[ParkingDepositPrice])"

How do I get the syntax to Sum the "ParkingDepositPrice" only when the field "PPDepPaid" (which is a Yes/No field) is equal to Yes or -1?

Any help is really appreciated. Thanks, Beth beth@integratedresourcemgmt.com
 
Beth,

How about the DSum function? Something like:
Code:
DSum("[ParkingDepositPrice]", "Prices", "[PPDepPaid]=-1")
 
Hi Cosmo - I tried that and it isn't working. The strange thing is that I have this calculation working:

"=IIf([PPDepPaid]=-1,[ParkingDepositPrice])"

When it is run per individual record. Any other suggestions?? Thanks and nice hearing from you. Beth beth@integratedresourcemgmt.com
 
I think your problem is that you have not defined a value when PPDepPaid is false, in this case you iif returns NULL and if you try to sum across a mix of nulls and numerics you will get NULL. Try this:

=IIf([PPDepPaid]=-1,[ParkingDepositPrice],0)

and then in the footer:


=Sum(IIf([PPDepPaid]=-1,[ParkingDepositPrice],0))

If you don't want to show the zeros you can mask them out
in the format property. Best Regards,
Mike
 
Sorry Beth, my bad - I forgot the equal sign:
Code:
=DSum("[ParkingDepositPrice]", "Prices", "[PPDepPaid]=-1")
This will work in the report footer........
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top