473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

IIf() Not Working in Access

I need to do the price in table [price] multiply by 1.20 if the price is higher then 150.
If the price is between 75 and 150 it have to multiply by 1.25.
Continue... continue... continue...
Expand|Select|Wrap|Line Numbers
  1. expr1: IIF([Price]>"150",
  2. [Price]*1.20,IIF([Price]>75,
  3. "[Price]*1.25",IIF([Price]>50,
  4. "[Price]*1.28",IIF([Price]>30,
  5. "[Price]*1.35",IIF([Price]>15,
  6. "[Price]*1.45",IIF([Price]>0,
  7. "[Price]*1.6"))))))
What do I do wrong?
Jan 10 '14 #1
4 1207
Seth Schrock
2,965 Expert 2GB
Try using the Switch function. It is used kind of like the Select Case statement in VBA.
Expand|Select|Wrap|Line Numbers
  1. expr1: Switch([Price]>150, [Price]*1.2,
  2. [Price] Between 76 and 150, [Price]*1.25,
  3. [Price] Between 51 and 75, [Price]*1.28,
  4. [Price] Between 31 and 50, [Price]*1.35,
  5. [Price] Between 16 and 30, [Price]*1.45,
  6. [Price] Between 1 and 15, [Price]*1.6)
In looking at your code closer, I notice that you have your double quotes used differently in some of the IIFs. Also, since you are using numbers, you don't need double quotes (SQL uses single quotes for text anyway) unless you are wanting [Price]*1.35 to be what gets returned. This is probably why your code isn't working. I think that the Switch function would be cleaner code and more easily readable, but yours should work if you remove all the double quotes.
Jan 10 '14 #2
MikeTheBike
639 Expert 512MB
Try removing the quotation marks. They are not need with numeric fields.
ie
Expand|Select|Wrap|Line Numbers
  1. expr1: IIF([Price]>150,[Price]*1.20,IIF([Price]>75,[Price]*1.25,IIF([Price]>50,[Price]*1.28,IIF([Price]>30,[Price]*1.35,IIF([Price]>15,[Price]*1.45,IIF([Price]>0,[Price]*1.6))))))
Also, what happens when [Price] <= 0 ?

HTH


MTB
Jan 10 '14 #3
Thanks for your reply's. There is no <=0, I'm almost there but now it says an error at the second [price]. I found some one who can support me personal. but you helped me alot thanks again!
Jan 10 '14 #4
NeoPa
32,556 Expert Mod 16PB
I'd use Seth's approach, but would maybe simplify the logic even further :
Expand|Select|Wrap|Line Numbers
  1. Expr1: Switch(
  2. [Price]>150, [Price]*1.2,
  3. [Price]>75, [Price]*1.25,
  4. [Price]>50, [Price]*1.28,
  5. [Price]>30, [Price]*1.35,
  6. [Price]>15, [Price]*1.45,
  7. True, [Price]*1.6)
As everyone's already said, your main problem is with the quotes. They are not appropriate for what you're doing.
Jan 10 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Station Media | last post by:
Hi, here my problem, i use stored procedure in ACCESS database(latest version), and i would like to use this procedure but it doesnt work, do you know why ? Procedure: PARAMETERS MyField Text...
3
by: Clouds | last post by:
Hi ! How do I add the dynamic event handler for a dropdownlist present in the itemtemplate of a datalist !! I am doing it in the itemdatabound event of the datalist but it doesnt work... I am...
2
by: thechaosengine | last post by:
Hi eveyone, If anyone could advise on the following I would be truly greatful: I have a fairly standard set up. An IIS 5.1 website set up with anonymous access allowed in all areas of the site...
0
by: Juna | last post by:
I have been working in vs2003, but now started to work in vs2005 but the problem, I have simple web application not website, which work i mean open in browser when we press F5 or run the...
1
Digital Don
by: Digital Don | last post by:
I am writing a program for Peg solitaire... To check for no repetition of previous states I use a Set for storage of Board states.. The pronblem is when I declare the set as type char i.e. set...
3
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it...
3
by: thread | last post by:
hi all, i'm trying to hide by database with this code: Application.CurrentDb.TableDefs(CurrentDb.TableDefs(i).Name).Properties("Attributes").Value = dbhiddenobject from some reason it doesnt...
1
by: Dany13 | last post by:
hi all. i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for...
20
by: Hush | last post by:
Hi, The following code works fine in IE7 but FF returns with an error: Access denied to achieve the property Element.firstChild. In this line: nodes = xmlDoc.documentElement.childNodes; My...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.