473,513 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query: setting a condition on a calculated field

I use Access 2007 and create queries with a number of calculated
fields/expressions (I'm still a novice so please forgive me if my
wording is imprecise...), like: MyCalculation = Field1 - Field2.

However, I noticed that I cannot query the database setting a
condition on this newly created field (eg <0); if I do, when I run the
query , Access shows me an input box asking for the value of
MyCalculation. The only solution I managed to find is to create yet
another query and set the filter there, but this seems a rather clumsy
and inefficient way to me.

Is there a better way?

Thanks!

Oct 12 '07 #1
3 5994
With any numeric calculations, it is usually best to use the Null to Zero
Function Nz()

Try MyCalculation = Nz(Field1) - Nz(Field2)
Phil

<my********@googlemail.comwrote in message
news:11**********************@v29g2000prd.googlegr oups.com...
>I use Access 2007 and create queries with a number of calculated
fields/expressions (I'm still a novice so please forgive me if my
wording is imprecise...), like: MyCalculation = Field1 - Field2.

However, I noticed that I cannot query the database setting a
condition on this newly created field (eg <0); if I do, when I run the
query , Access shows me an input box asking for the value of
MyCalculation. The only solution I managed to find is to create yet
another query and set the filter there, but this seems a rather clumsy
and inefficient way to me.

Is there a better way?

Thanks!

Oct 13 '07 #2
my********@googlemail.com wrote:
I use Access 2007 and create queries with a number of calculated
fields/expressions (I'm still a novice so please forgive me if my
wording is imprecise...), like: MyCalculation = Field1 - Field2.
Well, that IS imprecise ;-) In the query designer it would be written in an
empty colum as...

MyCalculation: Field1 - Field2

....while in SQL it would be written as...

Field1 - Field2 AS MyCalculation
However, I noticed that I cannot query the database setting a
condition on this newly created field (eg <0); if I do, when I run the
query , Access shows me an input box asking for the value of
MyCalculation. The only solution I managed to find is to create yet
another query and set the filter there, but this seems a rather clumsy
and inefficient way to me.

Is there a better way?
In the query designer just entering "<0" in the criteria row underneath your
calculated field should work fine. In SQL you would however not refer to the
name you gave the calculated field. You would repeat the expression like...

SELECT Field1
Field2
Field1 - Field2 AS MyCalculation
FROM SomeTable
WHERE Field1 - Field2 < 0

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Oct 13 '07 #3
In the query designer just entering "<0" in the criteria row underneath your
calculated field should work fine.
It does not. If I try it, when I run the query I get a small window
asking me for the value of MyCalculation ("Enter parameter value").
The same happens if I try to sort the calculated field (while in
design view).
I tried this a number of times in a number of differente queries and
databases, and the result has always been the same. Is it possible
that Access lets you neither set conditions nor sort calculated
fields?

Thanks!
Oct 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2239
by: Jerome | last post by:
Hi, I've got the following problem: I want my ASP page to display a certain number (based on a COUNT query), it works fine if the result is at least 1! If there are no records to be counted...
3
4969
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
3
7012
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
1
2323
by: Norbert Lieckfeldt | last post by:
MS Access 2002 here. I am just trying to set up a simple database for a friend who's an optician. Basically, all clients with address details, date of last eyetest and a drop-down combo box to...
7
2429
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
2
2308
by: Norbert Lieckfeldt | last post by:
I am setting up a database for a friend who's an Optician, using MS Access 2002. All seems to be working well, but I have hit a snag. There's a calculated field both in a form and a query which...
9
3030
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
10
6200
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
14
3818
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database for inventory control. I am setting up a form (frmProducts) for the viewing and adding of product information. I have several tables that this...
0
7160
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
7384
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,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.