Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if Null change it into zero 2

Status
Not open for further replies.

lanelouna

Programmer
Dec 19, 2002
71
GB
hello everyone
i need your help on this if you can
it was working, and somehow, for a reason i don't know
it stopped working
i have a recordset, and i am trying to sum the values in the fields, (the fields name is [closed 1], [closed 2]...
startP is an integer as well as endP
knowing that sometimes i may have no values at all in these fields, i had to use "if" in order to put the value 0 instead of Null, however, what is weird is that when it is null, he doesn't go inside the if at all
(the closed fields have dbinteger as type)

For j = startP To endP
RS.Edit
clsFieldname = "[closed " & j & "]"
If ((RS.Fields(closedFieldname) = Null)) Then
RS.Fields(closedFieldname) = 0
End If
k = k + RS.Fields(clsFieldname)
Next j

can anyone help me on this?
thank you
Lina Chebli
 
Wrap whatever you need to in the Nz (NullZero) function. It will return zero for a numeric field or vbNullString for a text field.

Good Luck!
 
Hi Lina,

try the standard Nz() function....
It will change the value of a variable to another value if it is Null.

For j = startP To endP
RS.Edit
clsFieldname = "[closed " & j & "]"
k = k + nz(RS.Fields(clsFieldname), 0)
Next j
Grtz,

Kalin
 
thank you both!
it worked!
you made my day :)
i appreciate it
thanks again

Lina Chebli
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top