M
Mike
I know this is a bit lengthly, so please be patient.
I am currently running Access 2003 and have a “split†database. I am aware
that Access has a problem with totaling up time that is over 24 hours. So
with the help of a Microsoft Help and Support forum, I was able to create and
use the code that is listed below. And it works great.
Function GetBikePatrolTotal()
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("BIKE PATROL")
interval = #12:00:00 AM#
While Not rs.EOF
interval = interval + rs![COMPLETE TOTAL TIME]
rs.MoveNext
Wend
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
hours = totalhours Mod 24
minutes = totalminutes Mod 60
GetBikePatrolTotal = totalhours & " hours and " & minutes & " minutes"
End Function
However, what I have noticed is that it will only works with the main table,
which will give me the Total Time since the start of the table which is now
holding about (2) years of information.
I have set up queries to be able to pull Monthly, Yearly, or Quarterly
reports for any of our Tables that are needed.
I am unable to get the above code to work with a query, even with using the
name of the query in place of the name of the table.
The code using the name of the query was looking like this:
Function GetBikePatrolTotal()
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("qryBikePatrolByYear")
interval = #12:00:00 AM#
While Not rs.EOF
interval = interval + rs![COMPLETE TOTAL TIME]
rs.MoveNext
Wend
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
hours = totalhours Mod 24
minutes = totalminutes Mod 60
GetBikePatrolTotal = totalhours & " hours and " & minutes & " minutes"
End Function
Am I doing something wrong? Or is it just not possible? Since I am new to
VBA and using code, I would not be surprised if I am doing something wrong.
Thank You,
Mike
I am currently running Access 2003 and have a “split†database. I am aware
that Access has a problem with totaling up time that is over 24 hours. So
with the help of a Microsoft Help and Support forum, I was able to create and
use the code that is listed below. And it works great.
Function GetBikePatrolTotal()
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("BIKE PATROL")
interval = #12:00:00 AM#
While Not rs.EOF
interval = interval + rs![COMPLETE TOTAL TIME]
rs.MoveNext
Wend
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
hours = totalhours Mod 24
minutes = totalminutes Mod 60
GetBikePatrolTotal = totalhours & " hours and " & minutes & " minutes"
End Function
However, what I have noticed is that it will only works with the main table,
which will give me the Total Time since the start of the table which is now
holding about (2) years of information.
I have set up queries to be able to pull Monthly, Yearly, or Quarterly
reports for any of our Tables that are needed.
I am unable to get the above code to work with a query, even with using the
name of the query in place of the name of the table.
The code using the name of the query was looking like this:
Function GetBikePatrolTotal()
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("qryBikePatrolByYear")
interval = #12:00:00 AM#
While Not rs.EOF
interval = interval + rs![COMPLETE TOTAL TIME]
rs.MoveNext
Wend
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
hours = totalhours Mod 24
minutes = totalminutes Mod 60
GetBikePatrolTotal = totalhours & " hours and " & minutes & " minutes"
End Function
Am I doing something wrong? Or is it just not possible? Since I am new to
VBA and using code, I would not be surprised if I am doing something wrong.
Thank You,
Mike