I am dividing Field_A by Field_B. But the problem is that sometimes Field_A is NULL (doesn't have any value). How can i check for that?
If it is Null, i guess the result should be 0 or Null.
I am dividing Field_A by Field_B. But the problem is that sometimes Field_A is NULL (doesn't have any value). How can i check for that?
If it is Null, i guess the result should be 0 or Null.
Use an IIF (inline If statement) in the expression:
=IIF(<Condition>,<TruePart>,<FalsePart>)
=IIF(Field_A Is Nothing OR Field_B = 0, 0, Field_A/Field_B)
This way, you are making sure that Field_A is not null and Field_B is not zero, to also avoid divide by zero errors.
The Easiest Method is to simply add a very small value to potential null value/zero value So :
=IIF(Field_A Is Nothing OR Field_B = 0, 0, Field_A/( Field_B + .000001))
This will still give you 0 when the value is either null or zero, but will prevent the #error from showing up when the denominator is otherwise null or zero
Also : Be careful to make sure that your types are the same; meaning, if the data type of your Field_A is decimal or double, make sure that you cast the small amount .000001 to CDec(.000001)
I have found that making sure that all types in your expression are the same is key to avoiding the #Error message
Yes, I think what "Jammie F" has commented above is correct.If Field B is 0 then you will get Divide by zero error. What you can use is:-
iif(Field_B=0,0,Field_A/Field_B)