473,401 Members | 2,125 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,401 software developers and data experts.

How to set negative numbers to 0

28
I have an inventory database part of which does a small auto calculation, by subtracting the number received from the number ordered. See below!
=[Products Subform].Form!UnitsOnOrder

The problem is when i receive something without ordering it my calculation box ends up with a minus number.
Is there a way to set all minus figures to zero?
Mar 8 '10 #1
6 8414
TheSmileyCoder
2,322 Expert Mod 2GB
Well you could run a update query....

If you want it to automatically set it to zero, you could do:
Expand|Select|Wrap|Line Numbers
  1. =IIF([Products Subform].Form!UnitsOnOrder>0;[Products Subform].Form!UnitsOnOrder;0)
Mar 8 '10 #2
Ezzz
28
Sorry gave the wrong info last time. The expression:-
=[Products Subform].Form!UnitsOnOrder
is the control source. (Not ultimately sure what this is/does)
The actual formula used for the calculation is:-
=Sum(nz([UnitsOrdered])-nz([UnitsReceived]))
Is there a way to adapt this formula so that any negative numbers always read zero?
Sorry to mess you about, but my knowledge is very limited, the database is a a microsoft template thats adapted for use, as best i can.
Regards
Ezzz
Mar 9 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
The code I provided could easily be adapted for another field.
Basicly its checking if the field is larger then 0, and if not, it sets the field to 0. If it is larger, it just performs the calculation.
Expand|Select|Wrap|Line Numbers
  1. =IIF(Sum(nz([UnitsOrdered])-nz([UnitsReceived]))>0; Sum(nz([UnitsOrdered])-nz([UnitsReceived])); 0) 
  2.  
Mar 9 '10 #4
Ezzz
28
I have tried to input your formula see below:-
= IIf(Sum(nz([UnitsOrdered])-nz([UnitsReceived]))>0; Sum(nz([UnitsOrdered])-nz([UnitsReceived])); 0)
But it throws up an error saying it contains an invalid syntax?
I assume that trying to do this in the "Expression Builder" is the correct way to do this. But having never used it before I'm not sure if i am doing it correctly?
The only difference i can see is the IIf statement which i used from the "Built in functions" box of the expression builder, and then typed the rest in by hand.
Any ideas.
Ezzz
Mar 9 '10 #5
TheSmileyCoder
2,322 Expert Mod 2GB
Usually when you get that error, Access will position the cursor at the part with invalid syntax. Where is that?

It could be that you need to replace ; with, that might depend on your regional settings (If I had a penny for each time regional settings gave me a headache......).
Mar 9 '10 #6
Ezzz
28
You were spot on.
Have replaced the : with , and the formula now works a treat.
Many thanks.
Ezzz
Mar 9 '10 #7

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

Similar topics

19
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more...
7
by: pj | last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter whether they are truly positive or negative ? I am having to cast each column to varchar to find out if there are any...
4
by: Charles A. Lackman | last post by:
Hello, I have some textboxes that are doing addition: Dim AString As Double AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text =...
5
by: Subrahmanyam Arya | last post by:
Hi Folks , I am trying to solve the problem of reading the numbers correctly from a serial line into an intel pentium processor machine . I am reading 1 byte and 2byte data both positive...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
7
by: andreas.lydersen | last post by:
Hi! While communicating with a monitoring unit, I get some hex values representing degrees celcius from its probes. The values can be something like '19' or '7d'. To convert it to int, I do the...
11
by: drtimhill | last post by:
I'm just starting out on Python, and am stumped by what appears an oddity in the way negative indices are handled. For example, to get the last character in a string, I can enter "x". To get the...
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.