How to sum records between two dates on a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Emaline

    How to sum records between two dates on a form?

    I am responsible for tracking training hours each year for a number of employees.

    I have just developed a database that includes both the fields "date" (of training) and "hours" I want to sum the hours of training for each year. Say <01/01/2010 for this year and for years going forward either >=01/01/2011 and <=12/31/2011 or just >12/31/2010
  • gnawoncents
    New Member
    • May 2010
    • 214

    #2
    First, if your field is really named date, I recommend changing it to something else as "date" is a reserved word. Something like TrainingDate would work fine. That said, try this:

    I set up a table (YourTableName) and added two columns (hours and TrainingDate). I then created a form with two unbound controls: txtDateYear and txtTotalHours. In the after update field of txtDateYear I have the following code:

    Code:
    Private Sub txtDateYear_AfterUpdate()
    
    txtTotalHours = DSum("[hours]", "YourTableName", "[TrainingDate] Like '*" & [txtDateYear] & "'")
    
    End Sub
    When you type/select a year from txtDateYear it will automatically populate txtTotalHours with the total number of hours for that year.

    Let me know if you have any questions.

    Comment

    Working...