Overflow Error on Calculation

Morning all,

Trying to calculate the wieight on a punch in Microsoft Access (form) in order to calculate the transport charge.

I'm getting an overflow on the following line of code. Can anyone help me overcome this?

w_calc = 3.14159265 * (Me.ShankDiameter / 10) ^ 2 * Me.OverallLength * 7.8 / 10 * 4 * 1000

shankdiameter = 4
overalllength = 80

Thanks
Sean

LVL 1
SeanNijAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
tbsgadiConnect With a Mentor Commented:
try w_calc = CLNG(3.14159265 * (Me.ShankDiameter / 10) ^ 2 * Me.OverallLength * 7.8 / 10 * 4 * 1000)
0
 
tbsgadiCommented:
Hi SeanNij,

What Data_Type are w_calc ,shankdiameter & overalllength ? (integer,single etc)


Gary
0
 
SeanNijAuthor Commented:
w_calc is long
shankdiameter is single
overlength is single
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
SeanNijAuthor Commented:
nope - same error
0
 
NatchiketConnect With a Mentor Commented:
hmmm looks like maybe the 2 * Me.OverallLength * 7.8 / 10 * 4 * 1000 is getting multiplied together before the power is applied giving a large exponential whereas presumably it's (shankdiameter/2) squared.
try

3.14159265 * ((Me.ShankDiameter / 10) ^ 2) * Me.OverallLength * 7.8 / 10 * 4 * 1000)
0
 
peter57rConnect With a Mentor Commented:
w-calc is ?long?
Are you intentionally trying to lose the decimal part?

But I can't reproduce the problem in A2003.
All I'm doing is  this...

Private Sub Command4_Click()
Dim wcalc As Long
wcalc = 3.14159265 * (Me.Shankdiameter / 10) ^ 2 * Me.OverallLength * 7.8 / 10 * 4 * 1000
MsgBox wcalc
End Sub

msgbox shows...125463
0
 
SeanNijAuthor Commented:
Me.WeightPP = 3.14159265 * (Me.ShankDiameter / 10) ^ 2 * Me.OverallLength * 7.8 / (10 * 4 * 1000)
0
 
peter57rCommented:
That works for me as well.

Go into the immediate pane and try:

?3.14159265 * (4 / 10) ^ 2 *80 * 7.8 / (10 * 4 * 1000)
0
 
SeanNijAuthor Commented:
RunTime Error '6'
Overflow i use immediate window
0
 
peter57rCommented:
How peculiar...see attached

You are definitely using Access 2003?


Doc6.doc
0
 
tbsgadiCommented:
Check that you don't have any missing references
0
 
SeanNijAuthor Commented:
brand new database
started from scratch yesterday on it.

what i did was uninstall office service pack 3 yesterday, cuase since i installed it my Access keeps crashing in weird places.

since uninstalling been fine....except for this error now....
0
 
SeanNijAuthor Commented:
hmmm

Me.WeightPP = 3.14159265 * (Me.ShankDiameter / 10) ^ 2 * Me.OverallLength * 7.8 / (10 * 4 * CLng(1000))

works....

WTF!!!!!!!!!!!!!
0
 
peter57rCommented:
That might be an explanation.  I never moved to SP3 because of all the problems reported as soon as it was issued.
So my examples are all on sp2.


0
 
tbsgadiCommented:
You should install the hotfix for SP3
http://support.microsoft.com/kb/945674
0
 
SeanNijAuthor Commented:
Splitting points for all the input - but the Clng got me working!
Thanks!
0
 
tbsgadiCommented:
Glad you got it working!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.