473,378 Members | 1,309 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,378 software developers and data experts.

ACCESS iif statement won't work

6
Trying to have expression calculate in field 3;

If field 4 =0 then field 1 divided by field 2, otherwise field one minus (field 4 multiplied by field 5) divided by field 2

otherwise answer should be
Field 1 =114 Field 2 =10 Field 4 =14 Field 5=1 then the calculation in field 3 should =10 114-(14)=(answer 100)/10 =10,

but the answer is coming out to 112.6

Here is my expression;

IIf([Truss O/C -2]=0,[Length]/[Truss O/C -1],[Length]-([Truss O/C -2]*[# of Bays - 2])/[Truss O/C -1])
Oct 17 '13 #1
9 1496
Pamela
6
For clarification

Field 1 =Length
Field 2 =Truss O/C-1
Field 3 =#of Bays-1
Field 4 =Truss O/C-2
Field 5 =#of Bays-2
Oct 17 '13 #2
Rabbit
12,516 Expert Mod 8TB
Here's some math 101.

In mathematics, multiplication and division is calculated before subtration and addition. To change the natural order, you need to group the appropriate calculations using parentheses. The natural order of calculation is as follows, from left to right:
Parentheses, exponents, multiplication and division, subtraction and addition.

What you wrote comes out to: 114 - (14 * 1) / 10
Using the rules of math above, the calcuation at each step is:
Expand|Select|Wrap|Line Numbers
  1. 114 - (14 * 1) / 10
  2. 114 - 14 / 10
  3. 114 - 1.4
  4. 112.6
Therefore, if you want to calculate the subtration after the first multiplication and then the final division, you need to change the natural order with parentheses.
Expand|Select|Wrap|Line Numbers
  1. (114 - 14 * 1) / 10
  2. (114 - 14) / 10
  3. 100 / 10
  4. 10
Oct 17 '13 #3
Pamela
6
Great that works, but now I'm trying to add an 3rd bay spacing & qty. and again formula messes up.

To explain better we sell buildings that have truss spacing and sometimes a building can have up to 3 bay spacing sizes, I need the [# of Bays-1] to auto calculate when there are 0's in bay/truss 2 or and when only bay 2 has a value and when both bay 2 and bay 3 have a value.

eg.

Building 126 ft long 10 bays @ 10 Truss o/c, one bay @ 12 truss o/c and one bay at 14 truss o/c

I managed to make this work but when I changed qty to have a zero in bay 2 or 3 it should have recalculated to show a decimal in bay 1, but it just remained at 10.

I am brand new to access... the expressions are not like they are in excel formulas as I have it working in excel but it does not calculate properly in access
Oct 17 '13 #4
Rabbit
12,516 Expert Mod 8TB
Show us the formula. Obviously you've changed it. It's hard to tell you what is wrong in the formula when we can't see what you've changed.
Oct 17 '13 #5
Pamela
6
This works, IIf([Truss O/C -2]=0,[Length]/[Truss O/C -1],([Length]-[Truss O/C -2]*[# of Bays - 2])/10)

if I'm just using 1 or 2 bays but when I tried to repeat the otherwise formula for it to take into account 3rd bay it does not calculate properly.
Oct 17 '13 #6
Rabbit
12,516 Expert Mod 8TB
That's pretty much the same formula from before... Where's the third bay that you were talking about. I don't see it anywhere in the formula.
Oct 17 '13 #7
Pamela
6
I am asking for help on how to create the formula with a 3rd bay, obviously the ones I have tried do not work.
Oct 17 '13 #8
Pamela
6
Rabbit, thank you for your help... but I signed up to this site as a HELP forum, I didn't come here for condescending remarks like "here's some math 101" If I knew how to create the expressions in Access I wouldn't be here.

If you truly want to help people try doing it without talking down to them.
Oct 17 '13 #9
Rabbit
12,516 Expert Mod 8TB
I'm sorry if I sounded condescending, that was not my intent. Not everyone knows the order of operations in math and the way the formula was written pointed to a misunderstanding of the order of operations as the cause of why the formula didn't work the way you thought it would.

I was only trying to establish the rules that Access uses to evaluate a mathematical expression. The reason the expression in Access didn't work wasn't because of an Access issue, it was a mathematical issue. Which is why I explained the math. If it was an Access issue, I would have shared some Access 101 information so you understood what was going on in the expression.

As for the third bay, I wanted to see your attempts at implementing it so that I could explain how to fix it and why it works or doesn't work so that you can understand the root causes. Where as if I just gave you the answer, there's no knowledge gained and you'll be more likely to make the same mistake again.
Oct 17 '13 #10

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

Similar topics

3
by: Oliver Spiesshofer | last post by:
Hi, I have a script that calls an fopen() on an external URL. I can run the script from the server as an url fine. When however the script should be run from crontab, it does not work. I get ...
5
by: Catherine | last post by:
I am having a problem viewing asp pages on iis version 5.1 xp pro. HTML pages are viewable on http://localhost but .asp pages are not. I have created a test program called timetest.asp with the...
19
by: Allen Thompson | last post by:
sorry for the simple question, haven't done this in a while. when I use the following script it keeps displaying the value of "x" like a string. for example, if I type the number 7 in the prompt,...
0
by: Sebastian Sosna | last post by:
Hi there! iam trying a code snippet from MSDN heres the link : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/netds/creating_groups.asp ive tried the code but it...
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
1
by: Gary | last post by:
I have the following in my web.config.... <customErrors mode="RemoteOnly" defaultRedirect="Applicationerror.aspx"/> but, my error page does not display. Instead a 'Runtime Error' page...
14
by: squash | last post by:
The following code works fine in Firefox/Netscape but wont work in IE. I suspect the problem is with one of these two simple functions. If there is no obvious error Ill paste the entire code. ...
8
by: Mark12345 | last post by:
Hi folks, thanks for looking. I have a database that takes down order details. Each customer has there own priceid in the price table. the errors that I get say enter parameter value for:...
2
by: jcollins1991 | last post by:
im trying to make a program thats supposed to check whether 2 strings are anagrams of each other (anagram = same letters in both strings, but in different orders... "cool as wet art" , and "cs at...
2
by: Admiral | last post by:
Hi, Anyone knows how this works? I have made a textbox called Editbox1 and 10 buttons. b0, b1, b2 etc. What i want to do is when i press a button, b1 for example, a number 1 appears into...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.