Hello, I have copied the below code from either this site or microsoft's access help pages and it is doing exactly what it should. My problem is that i need to add an extra parameter to it but i am not sure how.
Basically the code is summing the field DURATION which is a date/field in the table tbl_Data. Duration contains data in the format of hh:mm:ss and represents the length of a phone call. The code sums this perfectly but i need to add the parameter of a [MONTH] as the tbl_Data contains records over multiple periods and I only want the code to sum duration for the selected month. What do i need to do in order to achieve this......??
Many Thanks.
Function TEST()
Dim db As DAO.Database, rs As DAO.Recordset
Dim totalhours As Long, totalminutes As Long
Dim days As Long, hours As Long, minutes As Long
Dim interval As Variant, j As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
Set rs = db.OpenRecordset("tbl_Data")
interval = #12:00:00 AM#
While Not rs.EOF
interval = interval + rs![Duration]
rs.MoveNext
End With
Wend
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
hours = totalhours Mod 24
minutes = totalminutes Mod 60
TEST = totalhours & " hours and " & minutes & " minutes"
End Function
Basically the code is summing the field DURATION which is a date/field in the table tbl_Data. Duration contains data in the format of hh:mm:ss and represents the length of a phone call. The code sums this perfectly but i need to add the parameter of a [MONTH] as the tbl_Data contains records over multiple periods and I only want the code to sum duration for the selected month. What do i need to do in order to achieve this......??
Many Thanks.
Function TEST()
Dim db As DAO.Database, rs As DAO.Recordset
Dim totalhours As Long, totalminutes As Long
Dim days As Long, hours As Long, minutes As Long
Dim interval As Variant, j As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
Set rs = db.OpenRecordset("tbl_Data")
interval = #12:00:00 AM#
While Not rs.EOF
interval = interval + rs![Duration]
rs.MoveNext
End With
Wend
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
hours = totalhours Mod 24
minutes = totalminutes Mod 60
TEST = totalhours & " hours and " & minutes & " minutes"
End Function