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

Totaling fields with Null Values

Hi All,

I have created a form that calculates a total of certain fields. All fields are in the format "real".

My total however does not work if any of my fields are left blank.
In other words, I have to actually enter a "0" in each of the blank fields to ensure that the total works.

Can you please advise on how to correct this?
It should do the following... if a field is left blank, then the respective field should automatically be assigned a "0" value.

Please get back to me regarding this as soon as possible.
Jan 23 '07 #1
3 2192
missinglinq
3,532 Expert 2GB
In Access anything + Null is Null. You get around this by using the NZ function, which converts a Null to Zero.

For example, Instead of using

Me.Text4.Value = Me.Text0.Value + Me.Text2.Value

use

Me.Text4.Value = Nz(Me.Text0.Value) + Nz(Me.Text2.Value)
Jan 23 '07 #2
NeoPa
32,556 Expert Mod 16PB
Nz Function
See AlsoApplies ToExampleSpecificsYou can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. For example, you can use this function to convert a Null value to another value and prevent it from propagating through an expression.

Nz(variant, [valueifnull])
The Nz function has the following arguments.

Argument Description
variant A variable of data type Variant.
valueifnull Optional (unless used in a query). A Variant that supplies a value to be returned if the variant argument is Null. This argument enables you to return a value other than zero or a zero-length string.
Note If you use the Nz function in an expression in a query without using the valueifnull argument, the results will be a zero-length string in the fields that contain null values.



If the value of the variant argument is Null, the Nz function returns the number zero or a zero-length string (always returns a zero-length string when used in a query expression), depending on whether the context indicates the value should be a number or a string. If the optional valueifnull argument is included, then the Nz function will return the value specified by that argument if the variant argument is Null. When used in a query expression, the NZ function should always include the valueifnull argument,

If the value of variant isn't Null, then the Nz function returns the value of variant.
Nz() can also be used a bit more flexibly. The ValueIfNull parameter can be non-zero if required and string fields too are handled.
Personally I prefer to set this parameter explicitly to show in the code exactly what's hapenning.
Nz() is a very valuable function to have available - especially from within SQL code.
Jan 24 '07 #3
ADezii
8,834 Expert 8TB
Hi All,

I have created a form that calculates a total of certain fields. All fields are in the format "real".

My total however does not work if any of my fields are left blank.
In other words, I have to actually enter a "0" in each of the blank fields to ensure that the total works.

Can you please advise on how to correct this?
It should do the following... if a field is left blank, then the respective field should automatically be assigned a "0" value.

Please get back to me regarding this as soon as possible.
As previously stated by Missingling, Nulls propagate through Expressions. If any part of an Expression evaluates to Null, the entire Expression returns Null:
Expand|Select|Wrap|Line Numbers
  1. (((A + B) / C) ^ D) + E = Null [if E = Null]
Jan 24 '07 #4

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

Similar topics

1
by: Dominic Marks | last post by:
Hi, (I apologise if this is the wrong list, I haven't posted to a postgresql.org mailing list before, general seemed like a good catch-all) I am trying to implement a centralised...
6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
1
by: RiesbeckP | last post by:
Hi All, I have a DB where there are customer numbers and a few other fields. I want to be able to pull all of the null records for a particular field as well as all the other customer numbers...
0
by: bunty.gopal | last post by:
I am trying to use the PreparedStatement's addBatch to load data in an ETL-like process into a table. There is a single prepared statement. The parameters are set on it and prepStmt.addBatch() is...
3
by: Ross McLean | last post by:
Hi all, I've been teaching myself C# for a new project at work. I have a bit of a background in c++ and java but never been what you could call a guru. I'm having some strange things happening...
3
by: DeanL | last post by:
Hi all, I'm currently pulling out my already thin hair and need a little help if possible. I have an Access 97 db that is used to store inspection information for different regions. My report...
4
by: NormAmst | last post by:
I have a list of CPU processing times and job durations for an entire department at work. There are 3 classifications I am maintaining. CPU time during peak hours , CPU time during non peak hours...
2
by: grinder332518 | last post by:
In my report, I am populating a column with values computed by different means. Eg Rows 1 to 8 : column contents are (fieldA + fieldB) Row 9 : column...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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
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,...

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.