Computations In Tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • playagain
    New Member
    • May 2007
    • 9

    Computations In Tables

    Hello please help me to calculate this one:

    I have a table containing this fields (name, project done, hours consumed)

    example:
    this is a table of a timesheet

    Code:
    ---------------------------------------------------------------------------
    | NAME |          PROJECT DONE |             HOURS CONSUMED |
    ---------------------------------------------------------------------------
    |  A       |          1               |             [B]5[/B]    |
    |  B       |          2               |             10  |
    |  B       |          3               |             12  |
    |  A       |          2               |             [B]8[/B]    |
    |  D       |          1               |             9    |
    |  D       |          3               |             3    |
    |  A       |          4               |             [B]6[/B]    |

    my problem is how to get the total no. of hours of only "A'" or only "B"
    for example: I want to get the total hours of "A"
    5+8+6=19 hours then multiply it to 10 so that I can get the total salary of "A" which is 10X19=190

    then the 190 should appear to the textbox of "A"
    example:

    A's Salary is : [190] <--- this is a text box inside a form


    ...


    Please help me please

    I'm using Access 2003


    THANKS and GODBLESS
  • damonreid
    Recognized Expert New Member
    • Jul 2007
    • 114

    #2
    I would say your best bet is to have two forms that call a module to do the calculation and store them in another table. This is what I tend to do.

    Module:

    [code=vb]Option Compare Database
    Calc_1()
    Total_Hours= (Forms("Form Name").FieldNam e * 1) + (Forms("FormNam e").FieldNam e* 1) ect...
    End Function[/code]

    Then when you open your form or make changes to a field just call the function Calc_1 and it will update the calculation in your new field. To work out a wage simply change the *1 to their hourly rate, then ensure you have a query that filters for only their values and open a form that will total all the hours and multiply by their rate.

    Comment

    • abolos
      New Member
      • Apr 2007
      • 65

      #3
      Originally posted by playagain
      Hello please help me to calculate this one:

      I have a table containing this fields (name, project done, hours consumed)

      example:
      this is a table of a timesheet

      Code:
      ---------------------------------------------------------------------------
      | NAME |          PROJECT DONE |             HOURS CONSUMED |
      ---------------------------------------------------------------------------
      |  A       |          1               |             [B]5[/B]    |
      |  B       |          2               |             10  |
      |  B       |          3               |             12  |
      |  A       |          2               |             [B]8[/B]    |
      |  D       |          1               |             9    |
      |  D       |          3               |             3    |
      |  A       |          4               |             [B]6[/B]    |

      my problem is how to get the total no. of hours of only "A'" or only "B"
      for example: I want to get the total hours of "A"
      5+8+6=19 hours then multiply it to 10 so that I can get the total salary of "A" which is 10X19=190

      then the 190 should appear to the textbox of "A"
      example:

      A's Salary is : [190] <--- this is a text box inside a form


      ...


      Please help me please

      I'm using Access 2003


      THANKS and GODBLESS

      Hi,

      Try to use the SUM.

      Select SUM(hours) from <tablename> where name = A

      This SQL statement will give you the summation of whatever A has. Then multiply it by 10 in a field. Last put the result in another field (10*19).
      Abolos

      Comment

      • playagain
        New Member
        • May 2007
        • 9

        #4
        where to put the sql?

        then after that how can i put the result in a textbox?

        THANKS for further replies

        :) :) :)

        Comment

        • playagain
          New Member
          • May 2007
          • 9

          #5
          Originally posted by damonreid
          I would say your best bet is to have two forms that call a module to do the calculation and store them in another table. This is what I tend to do.

          Module:

          [code=vb]Option Compare Database
          Calc_1()
          Total_Hours= (Forms("Form Name").FieldNam e * 1) + (Forms("FormNam e").FieldNam e* 1) ect...
          End Function[/code]

          Then when you open your form or make changes to a field just call the function Calc_1 and it will update the calculation in your new field. To work out a wage simply change the *1 to their hourly rate, then ensure you have a query that filters for only their values and open a form that will total all the hours and multiply by their rate.

          still can't get it :( :( :(

          kindly explain it further :)

          Where to put the codes... why 2 forms? what is a module?

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Originally posted by playagain
            where to put the sql?

            then after that how can i put the result in a textbox?

            THANKS for further replies

            :) :) :)
            If you open a form in design view and open the properties window you can change the record souce of the form to the sql statement

            Comment

            • abolos
              New Member
              • Apr 2007
              • 65

              #7
              Originally posted by playagain
              still can't get it :( :( :(

              kindly explain it further :)

              Where to put the codes... why 2 forms? what is a module?

              You also may try the SQL by creating a query and open the SQL view then past it there.

              Abolos

              Comment

              Working...