Query Calculated Field Problem: Is my solution good programming?

Debased

Registered User.
Local time
Today, 13:56
Joined
Mar 11, 2004
Messages
112
Many thanks to those who continue to make my job more easier and help me learn new programming skills!!! :D

I have a totals query that has calculated field which does not work if one of the fields it is based on is null. I created a work around (see below).

My question is: is this a good practice or will it blow up on me some time down the road!

1. This is the calculated field:

Percent: [Total Yes]/(([Num Recs]*10)-([NA]))

However, if NA is null, the calculation fails.

2. This is the field I created:

NA0: IIf([Total NA] Is Null,0,[Total NA])

3. then changed the calculated field to:

Percent: [Total Yes]/(([Num Recs]*10)-([NA0]))
This does work but I am concerned that it is a work around that may not be stable!!

Thanks.
 
It is good, but this one is even better:
Percent: [Total Yes]/(([Num Recs]*10)-(Nz([NA])))
Nz(FIELD) (Null --> Zero) replace any void by the number 0.
Nz(FIELD,VALUE) replace the void by the value given.
Ex: Nz([Name],"N/A")

Now, just make sure that you won't make any "Divide by 0" error.
 
Thanks Newman, I like it!!!! :D

The "divide by zero" problem can't happen in this instance.
 

Users who are viewing this thread

Back
Top Bottom