Code keeps snagging on nulls!

Slayboy

Registered User.
Local time
Today, 15:50
Joined
Apr 28, 2004
Messages
28
Hi I've got this piece of code in a procedure for calculating IRRs from a table of data and at first it was snagging when it came to a null value, so I put in an if to tell it to take a zero if the field is null, but it still seems to snag on it, when I look in the code it has set it to zero but it still halted the process.
Here is the bit of code:

If rec.Fields(Counter + 5) = Null Then
Values(Counter) = "0"
Else
Values(Counter) = rec.Fields(Counter + 5)
End If


It's the bit:

Values(Counter) = rec.Fields(Counter + 5)

that is highlighted when I look into the VB and when I hover over the Values(Counter) it says it is 0, so it seems like the if is working?

I have tried putting a zero into the field on the table and it works then so it can't be that it has a problem with the value 0? But I can't go through the table looking for all the nulls and replacing them as it is all automated.

I'm really stumped?
 
Last edited:
I'm thinking you are dealing with numerical values so:
Code:
If rec.Fields(Counter + 5) = Null Then
   Values(Counter) = [COLOR="SeaGreen"][B]"0"[/B][/COLOR]
Else
   Values(Counter) = rec.Fields(Counter + 5)
End If
...should really be:
Code:
If [COLOR="Red"]IsNull(rec.Fields(Counter + 5))[/COLOR] Then
   Values(Counter) = [COLOR="Red"][B]0[/B][/COLOR]
Else
   Values(Counter) = rec.Fields(Counter + 5)
End If
Have you looked at the Nz() function? Nz() was designed to return 0 if a Null is encountered. BTW, *nothing* is ever = to Null; even Null.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom