Totals Report issue

Sean75db

Registered User.
Local time
Today, 01:01
Joined
May 16, 2014
Messages
33
In my database i am building a totals report on each employee for a certain job they do, in the work for i have a start date and time and stop date and time, then i have a 3rd field that stores the calculated total time it took to do the work, it is a Short Time formated field. That all works great and gives me what i need. Now i am trying to build the report and i can not get the totals to add up correctly.My report is grouped by employee and i am trying to get a total for each then a group total on the footer.

For example on employee i know worked 79:01:00 hours but my report is giving me 12:42

My totals on the footer is giving me 1:12:00 when i know 290:49 hours is the total.

I have been using =Sum([Doc_Total_Time])

Thanks for any help.
 
Last edited:
First, you shouldn't store calculated values. Instead, you should do the calculations when you need them (i.e. in a query).

Second, you can't really count on Access to add up time correctly. Time values are numbers, very small numbers. As a time, 24 hours = 1, so 1 hour = 1/24 (~.042). When you store hours:minutes and try and add them up its about 1/24th of what you expect.

What you should do is create a query, do the calculations there using a DateDiff(http://www.techonthenet.com/access/functions/date/datediff.php) to determine minutes (because that's the smallest unit you want to report on). Then in the report you can use your Sum to add all those minutes up (i.e. 285) and then format that value to display it how you want (i.e 04:45).
 
I know that i shoudn't store some data but it was requested and that is what i have to work with, so i need a way to add up my [Total_Time field]. I get what you are saying about running a query and i am building a report so i am running a query for the report. DateDiff will not work correctly since i have to calculate work hours into this as well. and in addition i also have a [stop_time] that has to be taken out. i have tried to do this in a query before and it didn't work then.

Any other suggestions?

I am really starting to hate working with time lol
 
Last edited:
I know that i shoudn't store some data but it was requested and that is what i have to work with

When building a house no one says to the construction foreman--"I don't want any right angles in the foundation--less than 65 or more than 115". The right way to lay a foundation is the right way to lay a foundation. And frankly, if he came back and said "I think that's a horrible idea and will cause problems later in the process, but I will get right on it", I wouldn't let that guy near my house.

So, if you've imposed the wrong rules in the foundation of your database, well then its on you to live with them and build upon them.

With that said, the method I laid out is still possible. Just because you are storing the time value, doesn't mean you have to use it. My method will work as long as you have the Start and Finish times.
 
Did you even read what I posted, or did you just want to continue to sound condescending? I know i do not have use to the stored data, but again like i said before i can NOT use DateDiff since it will not calculate work hours. I can use use my work hours module up to a certain point. I can get the data using a query "Your Method" but when trying to use this in a report if fails, meaning the report will not run when trying to total just the expression nother else. I can run the query and it works and i can see what i would need to do to convert over.

Next time please worry more about helping somone then talking down to them or pointing out what they may or may not be doing wrong. It may help in the future to ask a few questions as to how somone is trying to accomplish a task.
 
Did you even read what I posted, or did you just want to continue to sound condescending?

Those aren't mutually exclusive. Now that's how you condescend!

And here's how you know I read your posts:

I don't know exactly how you are calculating work hours--you mention a module, so I assume you have a function and are passing it [StartDateTime] and [EndDateTime] and it is returning a time datatype. If that is correct, you need a similar function that returns an integer which represents minutes. That's the real key: you need an integer that tells you how many minutes. Add up the minutes, divide the total by 60 for hours and the remainder becomes the minutes portion of your output.

If you can't reconfigure the function yourself, post the code here and we can work through it.
 
Pefect,a direction i can work with. I am going to post a few things here for you to see, the first is the coding i use to get me times and the second is my module that way you can what i am currently doing and what works in order to move forward.

Format(Int(Workhours([Date_Complete_Package_Received], [Date_Processing_Completed]) - Nz([Stop_Time_(B)]) / 60), "00") & ":" & Format(Int(((Workhours([Date_Complete_Package_Received], [Date_Processing_Completed]) - Nz([Stop_Time_(B)]) / 60) * 3600 - (Int((Workhours([Date_Complete_Package_Received], [Date_Processing_Completed]) - Nz([Stop_Time_(B)]) / 60)) * 3600)) / 60), "00") & ":" & Format((((Workhours([Date_Complete_Package_Received], [Date_Processing_Completed]) - Nz([Stop_Time_(B)]) / 60) * 3600 Mod 60)), "00")

I use the above on an after update on one of my forms. I did this because the managers requested that they can see the times at a glance and if and when the export the data out to excel.

Public Function Workdays(ByRef StartDate As Date, ByRef EndDate As Date, Optional ByRef strHolidays As String = "Holidays") As Integer
' Returns the number of workdays between startDate
' and endDate inclusive. Workdays excludes weekends and
' holidays. Optionally, pass this function the name of a table
' or query as the third argument. If you don't the default
' is "Holidays".
On Error GoTo Workdays_Error
Dim nWeekdays As Integer
Dim nHolidays As Integer
Dim strWhere As String

' DateValue returns the date part only.
StartDate = DateValue(StartDate)
EndDate = DateValue(EndDate)

nWeekdays = Weekdays(StartDate, EndDate)
If nWeekdays = -1 Then
Workdays = -1
GoTo Workdays_Exit
End If

strWhere = "[Holiday] >= #" & StartDate _
& "# AND [Holiday] <= #" & EndDate & "#"

' Count the number of holidays.
nHolidays = DCount(Expr:="[Holiday]", _
Domain:=strHolidays, _
Criteria:=strWhere)

Workdays = nWeekdays - nHolidays

Workdays_Exit:
Exit Function

Workdays_Error:
Workdays = -1
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Workdays"
Resume Workdays_Exit

End Function

Public Function Workhours(ByRef StartDate As Date, ByRef EndDate As Date, Optional ByRef strHolidays As String = "Holidays") As Double
On Error GoTo Workhours_Error
Dim WorkDaysInt As Integer
Dim FirstDayTime As Double
Dim LastDayTime As Double
FirstDayTime = DateDiff("n", StartDate, Month(StartDate) & "/" & Day(StartDate) & "/" & Year(StartDate) & " 05:00:00 PM") / 60
LastDayTime = DateDiff("n", Month(EndDate) & "/" & Day(EndDate) & "/" & Year(EndDate) & " 08:00:00 AM", EndDate) / 60
If LastDayTime < 0 Then LastDayTime = 0
If CDate(Month(StartDate) & "/" & Day(StartDate) & "/" & Year(StartDate)) = CDate(Month(EndDate) & "/" & Day(EndDate) & "/" & Year(EndDate)) Then
Workhours = DateDiff("n", StartDate, EndDate) / 60
Else:
Workhours = (Workdays(StartDate, EndDate) - 2) * 9 + FirstDayTime + LastDayTime
End If
If Workhours < 0 Then Workhours = 0
Workhours_Exit:
Exit Function

Workhours_Error:
Workhours = -1
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Workhours"
Resume Workhours_Exit
End Function
Public Function Weekdays(ByRef StartDate As Date, ByRef EndDate As Date) As Integer
' Returns the number of weekdays in the period from startDate
' to endDate inclusive. Returns -1 if an error occurs.
' If your weekend days do not include Saturday and Sunday and
' do not total two per week in number, this function will
' require modification.
On Error GoTo Weekdays_Error

' The number of weekend days per week.
Const ncNumberOfWeekendDays As Integer = 2

' The number of days inclusive.
Dim varDays As Variant

' The number of weekend days.
Dim varWeekendDays As Variant

' Temporary storage for datetime.
Dim dtmX As Date

' If the end date is earlier, swap the dates.
If EndDate < StartDate Then
dtmX = StartDate
StartDate = EndDate
EndDate = dtmX
End If

' Calculate the number of days inclusive (+ 1 is to add back startDate).
varDays = DateDiff(interval:="d", _
date1:=StartDate, _
date2:=EndDate) + 1

' Calculate the number of weekend days.
varWeekendDays = (DateDiff(interval:="ww", _
date1:=StartDate, _
date2:=EndDate) _
* ncNumberOfWeekendDays) _
+ IIf(DatePart(interval:="w", _
Date:=StartDate) = vbSunday, 1, 0) _
+ IIf(DatePart(interval:="w", _
Date:=EndDate) = vbSaturday, 1, 0)

' Calculate the number of weekdays.
Weekdays = (varDays - varWeekendDays)

Weekdays_Exit:
Exit Function

Weekdays_Error:
Weekdays = -1
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Weekdays"
Resume Weekdays_Exit
End Function
Public Function WorkHoursFormat(Start_Time As Date, End_Time As Date, Optional Stop_Time As Double = 0) As String
WorkHoursFormat = Format(Int(Workhours(DateAdd("n", Nz(Stop_Time), Start_Time), End_Time)), "00") & ":" & Format(Int((Workhours(DateAdd("n", Nz(Stop_Time), Start_Time), End_Time) * 3600 - (Int(Workhours(DateAdd("n", Nz(Stop_Time), Start_Time), End_Time)) * 3600)) / 60), "00") & ":" & Format(((Workhours(DateAdd("n", Nz(Stop_Time), Start_Time), End_Time) * 3600 Mod 60)), "00")
End Function


The above is my work hours module i picked it someplace and adjusted as i have needed.

In the query i have ran to calculate this same thing this where i have gotten so far.
2: Workhours([Doc_Spec_Date_Started],[Doc_Spec_Date_Completed])-Nz([Stop_Time_(C)])

Thanks
 
I trust you're code, so I'm not going to look over it. I can see what I need, in that you have a function called 'Workhours' which returns a double. It's not minutes, but it returns fractional hours, so it will do.

So, how exactly are you stuck? You have the calculated field [2] which I assume does what you want. So why not add up all those [2] values in your report to get total hours?
 
I guess this were i am getting stuck, I found one issue that i was having that's what was causing the report to fail, so that i have now is -13022.33333333 as a returned Sum value. So the next step is to turn that into a usable representation
 
2: Workhours([Doc_Spec_Date_Started],[Doc_Spec_Date_Completed])-Nz([Stop_Time_(C)])

Create a new query and paste that into a field. Bring in all the necessary data sources and then bring down all the individual fields as well. That way you can quickly find the value that is wrong and see what inputs you are passing the Workhours function

Most likely an EndDate comes before a StartDate or something is null or 0.
 

Users who are viewing this thread

Back
Top Bottom