The problem is that 03:45 is 3:45 AM, not 3 hours and 45 minutes. You are
dealing with an elapsed time, which is not an actual Time value. A Time
value is a point in time, such as 24 June 2005 at 3:45 AM.
To handle this, you need to convert the entry into minutes (convert
everything to the smallest unit you're using to simplify the addition), add
up the minutes, then format it as desired. If you want to use the hh:nn
format, that's fine. Just remember that it is only that, a format, not a
value.
This can be done using a user defined function or possibly in the query
itself.
Example (user defined function):
Sum(ConvToMinut es(Nz(CStr([qryDateFilterTa skHours-Weekly].[HoursWorked]),"0:00")))
AS SumOfHoursWorke d
Public Function ConvToMinutes(s trTime As String) As Long
Dim strArray() As String
ReDim strArray(2)
strArray() = Split(strInput, ":")
ConvToMinutes = CInt(strArray(0 )) * 60 + CInt(strArray(1 ))
End Function
Another possibility that you may be able to do in the query without the user
defined function (untested):
Sum((Nz(Left(CS tr([qryDateFilterTa skHours-Weekly].[HoursWorked],
Nz(Len(CStr([qryDateFilterTa skHours-Weekly].[HoursWorked]), 0) - 3, 0) * 60)
+ Nz(Right([qryDateFilterTa skHours-Weekly].[HoursWorked], 2), 0))
Then format the result back to hours:minutes, you may want to do this in the
form or report that displays the answer instead of in the query.
Possible Control Source:
=SumOfHoursWork ed \ 60 & ":" & SumOfHoursWorke d Mod 60
Other options include making the field two fields, one for hours and one for
minutes. This would save splitting it into hours and minutes to do the
calculation (it would already be split), but the rest would be the same. You
would still multiply the hours by 60 then add them to the minutes.
--
Wayne Morgan
MS Access MVP
"Drum2001" <dr******@gmail .com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.com.. .
I have a table that tracks employee times. I have a column
[HOURSWORKED] (Date/Time).
Users, through a form, enter how long it takes them to complete a task.
For example, 03:45 = 3 hours and 45 mins.
I am running the following query:
SELECT Sum(Nz([qryDateFilterTa skHours-Weekly].[NumberOfComplet ions],0))
AS SumOfNumberOfCo mpletions,
Format(Sum(Nz([qryDateFilterTa skHours-Weekly].[HoursWorked],0)),"Short
Time") AS SumOfHoursWorke d
FROM ALLTasksFilter LEFT JOIN [qryDateFilterTa skHours-Weekly] ON
ALLTasksFilter. ItemName = [qryDateFilterTa skHours-Weekly].ItemName;
This query is designed to total all the times within a specific time
period. However, when the time goes over 24 hours, it does not give
the correct time anymore.
Any suggestions on what I may do to acomplish this?
Thank you for your assistance!