View Full Version : Solved: want to calucalate price using iff
msa969
06-01-2010, 04:26 AM
I have a report which will print a ticket.
On this report I have a textbox which is unbound.
in the textbox if I type price it gives the ticket price of £12.00. The report data is being derived from qryTicketDetails
However I want to calculate a discount if the ticket is brought by recommennded friend.This is the formula I have devised:
=IIf([Friend]=True,[price]*0.9, [price])
but it returns with error
#Error
#
please help thank you
If the friend field is a Yes/No tick box then try
=IIf([Friend]=-1,[price]*0.9, [price])
geekgirlau
06-02-2010, 03:14 AM
You might also want to check for nulls:
=IIf([Friend]=-1,nz([price],0)*0.9, nz([price],0))
msa969
06-02-2010, 04:51 AM
If the friend field is a Yes/No tick box then try
=IIf([Friend]=-1,[price]*0.9, [price])
Thank you it does work because the field is set to yes no
Also thank you geekgirlau I will do a test plan to see if it can have a null value, i think it can't as I setup a default value.
Cheers
geekgirlau
06-02-2010, 09:24 PM
Unfortunately even with a default value, users will often delete the value in a field (even if it's zero!). It's a good idea to always test for nulls - if your data doesn't contain any it still doesn't hurt, and it can help you avoid a whole heap of problems.
msa969
06-07-2010, 03:33 PM
Hello I have been working on adding a new customer to the tblcustomer which I have solved.
I want to come back to the calculated price. Things have not changed.
Here is the code which I have typed in the text field:
=IIf([Friend]=TRUE,[Forms]![frmFindSeats]![txtSeatPrice]*0.9,[Forms]![frmFindSeats]![txtSeatPrice])
In tblCustomer the field Friend is text field (design view). In datasheet view the tblCustomer the Friend field the data is held as TRUE or FALSE
This is the error:
On the right hand of textbox in form view I see - #Error
I think I should check for null values? Please remind me with the code? Thank you in advance
geekgirlau
06-07-2010, 07:58 PM
Exactly as stated in post #3:
=IIf([Friend]=TRUE,nz([Forms]![frmFindSeats]![txtSeatPrice],0)*0.9,nz([Forms]![frmFindSeats]![txtSeatPrice],0))
or possibly
=IIf([Friend]=-1,nz([Forms]![frmFindSeats]![txtSeatPrice],0)*0.9,nz([Forms]![frmFindSeats]![txtSeatPrice],0))
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.