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

Error in DSum calculation? 2

Status
Not open for further replies.

NSNewey

Programmer
Jun 29, 2005
125
GB
Hi,

I have a table containing part entries for a part.
Each part entry has a percentage and I want to issue a warning when the sum of percentages for a part exceeds 100.

The data type for the percentage field is Double.

The problem is that I have entered 2 parts and several part entries for each part. Both percentage sums add up to 100 but on one of the parts, the warning code is running as if it is over 100. Here is the code...

Code:
[green]    'check the total percent and warn if over 100[/green]
    Dim p As Double
    p = DSum("Percentage", "tPartEntry", "PartID = " & Me.txtParentRecordID)
    If p > 100 Then
        msgBox "Please note that the total percentage is over 100%"
    End If

I can absolutely assure you that the DSum("Percentage", "tPartEntry", "PartID = " & Me.txtParentRecordID) is 100. I have tested this on a calculator and by running a group query and entering it into the intermediate window. All results say 100.

Does anyone know why one part with entry percentages totalling 100 gets past this code but the other does not?
 
Replace this:
If p > 100 Then
with this:
If Abs(p - 100) > 0.00001 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks both.

I opted for PHVs method as a good fix but will read up on data types and change the doubles to decimal when I have a little more time.

Thanks again.

Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top