Adding Null Values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 3 textboxes ... Text1, Text2 and Text3.
Text1 and Text2 are sums and often have Null values
Text3 = Text1 + Text2

How can I add Text1 and Text2 so that any null values are treated as 0

Example Text1 = 3
Text2 is Null
Text3 = 3 + 0
 
Hi Ray

Try this

Nz(Text1) + Nz(Text2)


Press F1 and look up the Nz function for lots of information on this topic

Hope this helps
 
ooops, just read your post again and noticed you did say they text boxes,

sorry

this what you need

=Nz([Text1]) + Nz([Text2])
 
Use Nz(Me.Text1,0) + Nz(Me.Text2,0)
Nz(Me.Text) returns a zero length string. Although it will work correctly,
this syntax is more self documenting and it saves the time Access would take
to coerce the data type.

Also, always qualify objects. Text1 doesn't tell you much and if there is
also a field in the record source named Text1 will cause confusion. In
addition, Text1 is a horrible name. So what is Text1, what is it used for?
Good naming conventions prevents a lot of problems. Use meaningful names
with standard naming conventions. See this site
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp
 
The names were just for illustration purposes. No need to make the question
more confusing if there is no need to do so. Was easy to modify the response
to fit the real names. Have used the other suggestion you mentioned ie-
Nz(Me.Text1,0)

Klatuu said:
Use Nz(Me.Text1,0) + Nz(Me.Text2,0)
Nz(Me.Text) returns a zero length string. Although it will work correctly,
this syntax is more self documenting and it saves the time Access would take
to coerce the data type.

Also, always qualify objects. Text1 doesn't tell you much and if there is
also a field in the record source named Text1 will cause confusion. In
addition, Text1 is a horrible name. So what is Text1, what is it used for?
Good naming conventions prevents a lot of problems. Use meaningful names
with standard naming conventions. See this site:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

Wayne-I-M said:
ooops, just read your post again and noticed you did say they text boxes,

sorry

this what you need

=Nz([Text1]) + Nz([Text2])

--
Wayne
Manchester, England.
Not an expert
Enjoy whatever it is you do
 
Did not mean to confuse, only to help. I understand your use of of the names
for example purposes; however, you would not believe how many people use the
names assigned by Access as they are without making them meaningful.
I guess I am sensitive to it these days because I am remediating an
application that does just that. It make the code really hard to follow
because you can't tell for sure what something is.

Ray said:
The names were just for illustration purposes. No need to make the question
more confusing if there is no need to do so. Was easy to modify the response
to fit the real names. Have used the other suggestion you mentioned ie-
Nz(Me.Text1,0)

Klatuu said:
Use Nz(Me.Text1,0) + Nz(Me.Text2,0)
Nz(Me.Text) returns a zero length string. Although it will work correctly,
this syntax is more self documenting and it saves the time Access would take
to coerce the data type.

Also, always qualify objects. Text1 doesn't tell you much and if there is
also a field in the record source named Text1 will cause confusion. In
addition, Text1 is a horrible name. So what is Text1, what is it used for?
Good naming conventions prevents a lot of problems. Use meaningful names
with standard naming conventions. See this site:
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaraccess/html/msdn_20naming.asp

Wayne-I-M said:
ooops, just read your post again and noticed you did say they text boxes,

sorry

this what you need

=Nz([Text1]) + Nz([Text2])

--
Wayne
Manchester, England.
Not an expert
Enjoy whatever it is you do
 
Worked fine. I caught the error also. Access corrected your previous reply
automatically anyway. So many thanks
 
Back
Top