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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error IF Null

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
0
0
GB
How do I change this code to handle if the value equals 0.

Code:
 Me.LTVPercentage = Me.txtLTV

 

That depends on what you mean by [blue]handle[/blue].
What do you WANT to do?


Randy
 
Well the destination field is a percentage based on two other fields. it takes the calcuation from the txtLTV field and puts it into the LTVPercentage field.

However, if the two fields that work the percentage are both 0 then it throws an error

Runtime Error -2147352657

The value you entered isnt valid for this field
 

Perhaps you need the NZ function.
Something like this might work:
Code:
Me.LTVPercentage = NZ(Me.txtLTV,0)


Randy
 

I don't think the NULL is the problem.

Looks to me like what are doing is:[tt]

txtSomeField = 0 / 0 [/tt]

or[tt]

txtSomeField = 123.45 / 0 [/tt]

And that's what couses;
Runtime Error -2147352657
The value you entered isnt valid for this field


Have fun.

---- Andy
 
Correct Andrzejek.

So I have tried the Nz solution and didnt work. So how do I correct the division by zero as you mentioned.

I thought Nz does that but obviously not
 

You do not get NULL if you divide by 0, you get an error (actually, if you divide by 0 you get infinity, right? :) )

Just do not allow to divide by 0, show the message instead and insist on a value grater than 0, or do not calculate because you cannot.

Have fun.

---- Andy
 
Hi!

Wherever you are doing the division use an IIf like this:

IIf(YourDemnominator = 0, 0, YourNominator/YourDenominator)

Now any time the denominator is 0 you get 0%

hth

Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top