Consulting

Results 1 to 7 of 7

Thread: Solved: want to calucalate price using iff

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Posts
    22
    Location

    Solved: want to calucalate price using iff

    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

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    If the friend field is a Yes/No tick box then try
    =IIf([Friend]=-1,[price]*0.9, [price])

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    You might also want to check for nulls:

    =IIf([Friend]=-1,nz([price],0)*0.9, nz([price],0))

  4. #4
    VBAX Regular
    Joined
    Jun 2007
    Posts
    22
    Location
    Quote Originally Posted by OBP
    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

  5. #5
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    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.

  6. #6
    VBAX Regular
    Joined
    Jun 2007
    Posts
    22
    Location
    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

  7. #7
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    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))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •