Results 1 to 15 of 15
  1. #1
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    calculation of income tax

    Hi, I have a database that calculates payroll. (NOT IN the USA)
    The first table shows calculation for three persons.
    Sections of the Income Tax Table is also shown, where the gross for each person fall within.


    Note that if the person’s gross does not fall within the amount eg table says between $2,322.32
    And $2,322.51, but equals exactly the starting number the tax is not calculated. I assume the same would happen if it fell on the ending number also.
    The code to calculate the tax is at thebottom.
    Please for help in the coding.

    Income Tax Year Gross Pay
    1 $0.00 2012 $2,695.18
    2 $233.96 2012 $2,602.51
    3 $0.00 2012 $2,322.32
    TAX TABLES
    $2,322.12 $2,322.31 $101.40
    $2,322.32 $2,322.51 $101.45
    $2,322.52 $2,322.71 $101.50
    $2,602.18 $2,602.37 $233.91
    $2,602.38 $2,602.57 $233.96
    $2,602.58 $2,602.77 $234.01
    $2,602.78 $2,602.97 $234.06
    $2,694.98 $2,695.17 $257.11
    $2,695.18 $2,695.37 $257.16
    $2,695.38 $2,695.57 $257.21
    Taxes: (SELECT T.[TaxAmount] FROM IncomeTaxMonthly AS T WHERE [PayRoll Table].GROSS Between T.PayRangeLow And T.PayRangeHigh)

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Didn't do much except get rid of the spaces in the names. A2K format, but you should be able to open it.

  3. #3
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Hi Steve,
    Thanks. I see where it works in your DB, but it does not work in mine. I am not a pro, so my DB is kind of cluttered. Basically I have the Emp Records Table, and a Salary Particulars Table where the hours and other payments due are entered. A first calculation is done and the data is apended to a table called Payroll Data. Two queries are then run to calculate the pay, because certain persons get incentives, so those are calculated seperately, and that data is appended to the Payroll Table. Lastly a query is run to calculate the taxes and social security. I took out the space in the Payroll Table name, and in the query, but it does not work. Would you allow me to send you the DB?
    Regards

  4. #4
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    Calculation of Income Tax

    Hi Steve, I have attached. Hope you can look at it.

    Thanks
    Attached Files Attached Files

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by chavez_sea View Post
    Hi Steve, I have attached. Hope you can look at it.

    Thanks
    Tried opening it, but it asks for a password???
    Last edited by ssanfu; 03-30-2012 at 09:33 PM. Reason: computer can't spell

  6. #6
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Sorry, password is 2011

    Thanks

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Well, this has been fun! After a long night, I think I finally figured it out.

    But first, the obligatory recommendations. You shouldn't use reserved words as object names. See http://allenbrowne.com/AppIssueBadWord.html
    These are words such as "Name", "Names" & "Year". You shouldn't use spaces in object names (bad - Social Security Number, good - SocialSecurityNumber). You shouldn't use non alphanumeric characters (bad - "FTC #"); the underscore ( _ ) is OK ("FTC_Num").

    There are two reasons that the Income tax is not being calculated....
    1) The minimum wage amount for [PayRangeLow] value is $2,166.68. So any wage less that amount will return a tax amount of $0
    2) What you see for the field "Gross" is not the value that is in stored in the field. What you see might be $2,248.58, but what is stored is 2248.5848. In the "IncomeTaxMonthly", the two records are
    PayRangeLow PayRangeHigh TaxAmount
    $2,248.39 $2,248.58 $41.30
    $2,248.59 $2,248.78 $41.35

    It looks like the tax should be $41.30, but the actual Gross wage is more than that by .0048 cents. Yet it is also not 2248.59, so that tax amount is not returned either.
    The solution is to round the gross wage to 2 decimal places before calculating the income tax.

    I changed the "TAX" field in the query to:

    Code:
    Taxes: (SELECT T.[TaxAmount] FROM IncomeTaxMonthly AS T  WHERE int(([PayRoll Table].GROSS*100)+ .5)/100 Between T.PayRangeLow And T.PayRangeHigh)
    This works, but it takes the query several minutes (over 10) to execute. I also wrote a UDF that returned an Income Tax of $0 if the Gross was below $2,166.68. If the Gross was greater than $2,166.68, the Gross is rounded, then the tax amount is calculated. I'll have to post the UDF tonight.

    The best solution would be to have the "Gross" stored with 2 decimal places.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Public Function CalcTax(pGross As Currency) As Currency
       Dim d As DAO.Database
       Dim r As DAO.Recordset
       Dim sSQL As String
       Dim tmpGross As Currency
    
       Const MinWage As Currency = 2166.68      ' <= hard coded from tax table
    
       Set d = CurrentDb
       CalcTax = 0
       tmpGross = Int((pGross * 100) + 0.5) / 100
    
       If tmpGross >= MinWage Then
          sSQL = "SELECT [TaxAmount] FROM IncomeTaxMonthly WHERE " & tmpGross & " Between PayRangeLow And PayRangeHigh"
          Set r = d.OpenRecordset(sSQL)
    
          If Not r.EOF Then
             CalcTax = r("TaxAmount")
          End If
       End If
    
       On Error Resume Next
       r.Close
       Set r = Nothing
       Set d = Nothing
    
    End Function
    In the query, the tax column would look like this:

    Code:
    Taxes: CalcTax([GROSS])
    This executes in about < 5 seconds for approx 1042 records.


    Possible Modification:
    Instead of hard coding the min wage, you could run code on startup to initalize a glogal variable, then use that instead of the constant in the code.

  9. #9
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Thanks for your help.But......with my limited knowledge, I need guidance. Where do I put the code, would that be in the SQL in the query? Also I would need the code to read the gross from the Payroll Table as they were calculated for the pay period. Really I cant write code, all my simple querries are recorded when I do my query design. EVen this tax code that I currently have, I got help sometime back from this forum. There are usually about 90-105 employees at any one pay period.

    Thanks so much for your help.

    Looking forward to hearing from you.

    Cristina

  10. #10
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by chavez_sea View Post
    Thanks for your help.But......with my limited knowledge, I need guidance. Where do I put the code, would that be in the SQL in the query? Also I would need the code to read the gross from the Payroll Table as they were calculated for the pay period. Really I cant write code, all my simple querries are recorded when I do my query design. EVen this tax code that I currently have, I got help sometime back from this forum. There are usually about 90-105 employees at any one pay period.

    Thanks so much for your help.

    Looking forward to hearing from you.

    Cristina
    Put the code in a standard module.... Name the module something like "CodeCalcs" or "PayrollCalcs". Do not name the module the same as a subroutine.
    In the query "Salaries Register Report Append", change the tax column to:
    Code:
    Taxes: CalcTax([GROSS])

  11. #11
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105

    calculate tax---compile error

    Good day, I created a new module, copied the code. I changed the query for the taxes. When I tried to run, this is what came up, compile error. Please for some more help.

    Thanks
    Cristina
    Attached Files Attached Files

  12. #12
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Whenever you see "DAO" in code, it means there needs to be a reference to a library. In the IDE, go to TOOLS/REFERENCES, then scroll down to "Microsoft DAO 3.6 Object Library" and check it.

    In the attached mdb, I have the reference set, the code entered and the query modified.

    I also played around with your data entry form. I would suggest you work on your table structure before you go much further. You have a lot of make table queries - IMHO, way too many. This leads to mdb bloat and a greater chance of corruption.

  13. #13
    chavez_sea is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2011
    Posts
    105
    Hi Steve,

    Was out of the office for a while. Thanks very much for your help. I see that it works perfectly now.
    I will work on the tables as you suggested. I am still unable to look at the changes you made, as I cant find the IDE. I can see the change on the Query. My access is version 2010, I tried but can't find it, the MENU is different I would like to learn for future reference please. Thanks so much again. Great !!

  14. #14
    sazzad128 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    2
    Quote Originally Posted by ssanfu View Post
    Whenever you see "DAO" in code, it means there needs to be a reference to a library. In the IDE, go to TOOLS/REFERENCES, then scroll down to "Microsoft DAO 3.6 Object Library" and check it.

    In the attached mdb, I have the reference set, the code entered and the query modified.

    I also played around with your data entry form. I would suggest you work on your table structure before you go much further. You have a lot of make table queries - IMHO, way too many. This leads to mdb bloat and a greater chance of corruption.
    Hei whats the password?

  15. #15
    sazzad128 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    2
    Thanks I got it
    Password is 2011

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Rent income stream
    By liles in forum Access
    Replies: 2
    Last Post: 01-24-2012, 08:41 AM
  2. Calculation
    By sabrish72 in forum Reports
    Replies: 3
    Last Post: 06-06-2011, 12:41 AM
  3. Need help with calculation please
    By Gabriel984 in forum Forms
    Replies: 6
    Last Post: 09-09-2010, 12:06 PM
  4. Income and outcome
    By Leszek in forum Access
    Replies: 3
    Last Post: 01-07-2009, 11:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums