Access VBA error "Overflow" (1 Viewer)

daryll

Registered User.
Local time
Today, 00:11
Joined
Jan 2, 2018
Messages
49
Hi!

Why this code still throws an overflow error
Code:
IIf( (cbStatNotStarted=0 Or cbStatTotal=0), 0, (cbStatNotStarted / cbStatTotal) * 100 )
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 03:11
Joined
Apr 27, 2015
Messages
6,337
I suspect it has something to do with the numbers themselves. Can you provide an example of what kind of values are in the equation.

Also, you should always check for null and Zero values, especially if you are doing division.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 03:11
Joined
Apr 27, 2015
Messages
6,337
Apologies, forget about what I said regarding checking for Zero, I can see now that you have.

I tend to go off half-cocked...
 

Mark_

Longboard on the internet
Local time
Today, 00:11
Joined
Sep 12, 2017
Messages
2,111
Let me guess, your solution was
Code:
IIf( (nz(cbStatNotStarted,0)=0 Or nz(cbStatTotal,0)=0), 0, (cbStatNotStarted / cbStatTotal) * 100 )

so you could check for either zero OR null all in one fell swoop?
 

daryll

Registered User.
Local time
Today, 00:11
Joined
Jan 2, 2018
Messages
49
Let me guess, your solution was
Code:
IIf( (nz(cbStatNotStarted,0)=0 Or nz(cbStatTotal,0)=0), 0, (cbStatNotStarted / cbStatTotal) * 100 )

so you could check for either zero OR null all in one fell swoop?

This is the version I have

Code:
(IIf(cbStatNotStarted = 0, 0, cbStatNotStarted) / IIf(cbStatTotal = 0, 1, cbStatTotal)) * 100
 

plog

Banishment Pending
Local time
Today, 02:11
Joined
May 11, 2011
Messages
11,646
No need to test cbSTartNotStarted at all:


For all x<>0, 0/x = 0
 

Users who are viewing this thread

Top Bottom