Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 22nd, 2005, 02:44 PM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Correct currency totals

Hello all,

I am trying to total each line on a subform and end up with a grand total for a given record. However, the line totals will not add correctly which in turn gives me an incorrect grand total. Please review this info to see if a simple fix is evident.

The first 2 items perform as they should. All dollar amounts $XXX.0001 and over round to the next cent. This is what I want. The grand total code does not add the rounded values.


Private Sub UnitPrice_AfterUpdate()
    [LineSubTotal] = Me.Multiplier * Me.UnitPrice

End Sub
        [LineSubTotal] rounds correctly = Example 941 x $0.145 = $136.45
        [LineSubTotal] is set to 2 decimal places.


Private Sub SurchargePercent_AfterUpdate()
    [SurchargeTotal] = Me.LineSubTotal * Me.SurchargePercent / 100

End Sub
        [SurchargeTotal] rounds correctly = Example $136.45 x 4% = $5.46
        [SurchargeTotal] is set to 2 decimal places.



=Sum(Nz([LineSubTotal])+Nz([SurchargeTotal]))
    Does not add rounded currency correctly = Example $136.45 + $5.46 = $141.90

I have tried codes CLng, CCur, Rnd.:(

Thank you for your time!


D. Bartelt
__________________
D. Bartelt
Reply With Quote
  #2 (permalink)  
Old August 23rd, 2005, 08:50 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello again,

Some more info on my problem. The problem lies within the table. I have formatted the [LineSubTotal], [SurchargeTotal] and [LineTotal] fields to be currency with 2 decimal places. The fields show 2 decimal places until I click on that field. At that point it shows 3 - 4 decimal places. The codes I have written will not take the visible value, they take the true value. How can I force 2 decimal places that will go to the next cent? If it is $00.0101, I need to force it to $00.02.

Thanks.

D. Bartelt
Reply With Quote
  #3 (permalink)  
Old October 16th, 2005, 12:58 AM
Friend of Wrox
 
Join Date: Jul 2005
Location: Oklahoma City, OK, USA.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The currency data data tyoe always has 4 decianls place to handle rounding.

If you do not want tis, you must round all the data going into the table to 2 places or in your formulas, rond each field to 2 places before doing any calculation.



Boyd
"Hi Tech Coach"
Access Based Accounting/Business Solutions developer.
http://www.officeprogramming.com
Reply With Quote
  #4 (permalink)  
Old October 17th, 2005, 07:40 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Boyd,

Thanks for your reply. I found what I was looking for at Microsoft.com, Access help. I wrote this module in my database and it performs just as I was hoping.

My calculations use the "RoundCC" function. Ie. =Sum(RoundCC(Nz([Multiplier])*Nz([UnitPrice])*Nz([SurchargePercent])/100))


'************************************************* ********************
' Declarations section of the module
'************************************************* ********************

Option Compare Database
Option Explicit
Const Factor = 100

'************************************************* ********************
'RoundAU and TruncAU are designed to be added to the
'AfterUpdate property on a form control.
'************************************************* ********************
Function RoundAU(X As Control)

    X = Int(X * Factor + 0.5) / Factor

End Function
Function TruncAU(X As Control)

    X = Int(X * Factor) / Factor

End Function

'************************************************* ********************
' RoundCC and TruncCC are designed to be used in
' expressions and calculated controls on forms and reports.
'************************************************* ********************

Function RoundCC(X)

    RoundCC = Int(X * Factor + 0.5) / Factor

End Function

-----------

Hope this helps others in need of correct currency rounding.

Have a good day!:)

D. Bartelt
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Report totals rwahdan BOOK: Access 2003 VBA Programmer's Reference 2 February 5th, 2008 03:56 AM
Help with totals rsm42 ASP.NET 1.0 and 1.1 Basics 0 December 15th, 2006 01:18 PM
Grouping and totals btado XML 4 July 1st, 2005 03:08 AM
Grouping and totals btado XSLT 3 June 22nd, 2005 01:08 AM
Totals bjackman Access 1 February 8th, 2004 09:27 PM



All times are GMT -4. The time now is 12:55 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.