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

Calculation based on If...Then Statement

4
I have a question about how to perform a calculation. I'm using Access 2003 in Windows XP.

I have three fields of different measurements, which I'll call A, B, and C. Those numbers get crunched to yield X, Y, and Z, respectively, in a query. No problem so far. What I want to do next is calculate N, but how I do that depends on the value of A/B:

If A/B >30
Then N=(Y+Z)/2

If A/B <10
Then N=(X+Z)/2

If 10<= A/B <=30
Then N=( (X+Y)/2 + Z)/2

Can I make this happen in a query?

I've tried various ways of entering If...Then...ElseIf..., with different combinations of parentheses and brackets to separate terms, but I keep getting an error that says "The expression you entered contains invalid syntax. You may have entered an operand without an operator." After I click OK, my first Then in the statement is highlighted.

I would appreciate any help in getting this calculation to work. I'm still new at Access, so please give step-by-step instructions if you can. Many thanks!
Mar 20 '07 #1
6 4927
Rabbit
12,516 Expert Mod 8TB
What's the code you're using? You can't just use an if/then in a query. You have to use iif(expression, value if true, value if false).
Mar 20 '07 #2
KimC
4
What's the code you're using?
This is my latest attempt in the query's design view:
TSI: If ([TNdTP]>30) Then (([TSITP]+[TSISD])/2)
[Else (([TSITN]+[TSISD])/2)]

When I change that If to iif, it gives me this error: The expression you entered has a function containing the wrong number of arguments.
Mar 20 '07 #3
Rabbit
12,516 Expert Mod 8TB
It looks like you replied before I made my edits. You'll need to use the iif() function. And you can nest them within each other as a quick fix.
Mar 20 '07 #4
Rabbit
12,516 Expert Mod 8TB
This is my latest attempt in the query's design view:
TSI: If ([TNdTP]>30) Then (([TSITP]+[TSISD])/2)
[Else (([TSITN]+[TSISD])/2)]

When I change that If to iif, it gives me this error: The expression you entered has a function containing the wrong number of arguments.
Well, you can't merely change If to iif because the syntax would be wrong.
Expand|Select|Wrap|Line Numbers
  1. TSI: iif ([TNdTP]>30, [TSITP]+[TSISD])/2, [TSITN]+[TSISD])/2)
Mar 20 '07 #5
KimC
4
Using nested iif statements makes it work. Thanks so much!
Mar 20 '07 #6
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Mar 20 '07 #7

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

Similar topics

5
by: Michael Hagstrom | last post by:
Good Day - I have written a form which collects input for a fare calculation. The form collects the following: 1) Departure or Destination Group (1,2,or 3) 2) Number of Adults 3) Number of...
1
by: Gx | last post by:
I have this form with the fields: * Product: (drop down combo box) with choices - X, Y * Amount: (currency ) * Balance (currency) I want to associate product X with the percentage...
5
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, that has the following code for its On Open event. =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-= Private Sub Form_Open(Cancel As Integer) ...
15
by: Pres | last post by:
I am not an experienced programmer. I do have a question regarding workday calculations. I have 3 fields. CURDATE, NUMDAYS, CALCDATE After entering the first two fields, normally the current...
4
by: vg-mail | last post by:
Hello all, I have identical design for form and report but I am getting calculation error on form and everything is OK on report. The form and report are build up on SQL statement. The...
4
by: sara | last post by:
i am studying a computer engineering and i started taking programming using C++ since month i have question i think it`s easy for you all *prof.programmer* but it`s bit diffecult for me plzz i...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
1
by: Colin Clark | last post by:
Hello, I have a database of scores for a sports club. I want to display a continuous subform showing a person's scores for the season along with a running calculation based on those scores (the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.