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

source code problem in access forms

Status
Not open for further replies.

sfc85

Programmer
Mar 16, 2003
8
KW
Below is a source code I am using to calculate the cost of goods for a company. But every time the user clicks enter to move forward and activate this formula, I receive a message “Runtime Error ‘6’ Overflow”. After debugging, the highlighted formula is the Me.UL Cost line shown below.

Any suggestions for a solution?

Thank you

rami

source code:

Private Sub Unit_Cost_LostFocus()
Me.Tot_Cost = Me.Unit_Cost * Me.Qty
Me.Disc_Cost = (Me.Tot_Cost) - ((Me.Tot_Cost * [Forms]![PO Header].[DISC]) / [Forms]![PO Header].[FCAMT])
Me.UL_Cost = (Me.Disc_Cost * (1 + [Forms]![PO Header].[Factor]) * [Forms]![PO Header].[RATE]) / Me.[Qty]
Me.TLCOST = Me.Disc_Cost * (1 + [Forms]![PO Header].[Factor]) * [Forms]![PO Header].[RATE]
End Sub


 
Several things that you might want to do.

First I would insure that you are not dealing with a Division by 0 condition
Code:
if ([Forms]![PO Header].[FCAMT] <> 0) Then
   Me.Disc_Cost = (Me.Tot_Cost) - ((Me.Tot_Cost * [Forms]![PO Header].[DISC]) / [Forms]![PO Header].[FCAMT])
else
   msgbox &quot;some error condition&quot;
End If
and a check for Me.Qty as well.

You also may want to force the calculations to take place using double precision by using the CDbl function.
Code:
Me.UL_Cost = (CDbl(Me.Disc_Cost) * (1# + CDbl([Forms]![PO Header].[Factor])) * CDbl([Forms]![PO Header].[RATE])) / CDbl(Me.[Qty])


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks cajun

you're a lifesaver. it worked!

rami
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top