H
Henro
I have the following code that calculates totals of short times.
To be more precise: it adds all the hours somebody worked more than
he/she should have and totals them.
Now this funny thing happens: as soon as somebody works less than
he/she should one EXTRA hour gets added.
Example: Edwin works three days, the third day he works one hour too
much, (not probable ;p), that goes fine. But as soon as he works less
than he should (very probable ;p) one hour extra gets subtracted. So
let's say he worked 8:30 instead of 9:00, he should have a total of
minus half an hour. But he gets a total of -1:30. It doesn't matter
how often he works too much or to less. As soon as he works too less
for one day one hour too much gets substracted.
So, i.e. regardless if he works ten days ten hours too little, as soon
as he has one day of negative total there is one negative hour too
much.
------------------------CODE-----------------------------
Function TotME(varFieldName As Variant) As String
On Error GoTo ProcError
Dim db As DAO.Database, rs As DAO.Recordset
Dim totaaluren As Long, totaalminuten As Long
Dim uren As Long, minuten As Long
Dim Interval As Variant, j As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
Set rs = db.OpenRecordset("Uren tbv verzamelengineer")
Interval = #12:00:00 AM#
rs.MoveFirst
While Not rs.EOF
If Not IsNull(rs(varFieldName)) Then
Interval = Interval + rs(varFieldName)
End If
rs.MoveNext
Wend
totaaluren = Int(CSng(Interval * 24))
totaalminuten = Int(CSng(Interval * 1440))
uren = totaaluren Mod 24
minuten = totaalminuten Mod 60
TotME = totaaluren & ":" & minuten
ExitProc:
On Error Resume Next
rs.Close
db.Close
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
, "Uren kunnen niet worden getotaliseerd..."
Resume ExitProc
End Function
-------------------------CODE----------------------------------
To be more precise: it adds all the hours somebody worked more than
he/she should have and totals them.
Now this funny thing happens: as soon as somebody works less than
he/she should one EXTRA hour gets added.
Example: Edwin works three days, the third day he works one hour too
much, (not probable ;p), that goes fine. But as soon as he works less
than he should (very probable ;p) one hour extra gets subtracted. So
let's say he worked 8:30 instead of 9:00, he should have a total of
minus half an hour. But he gets a total of -1:30. It doesn't matter
how often he works too much or to less. As soon as he works too less
for one day one hour too much gets substracted.
So, i.e. regardless if he works ten days ten hours too little, as soon
as he has one day of negative total there is one negative hour too
much.
------------------------CODE-----------------------------
Function TotME(varFieldName As Variant) As String
On Error GoTo ProcError
Dim db As DAO.Database, rs As DAO.Recordset
Dim totaaluren As Long, totaalminuten As Long
Dim uren As Long, minuten As Long
Dim Interval As Variant, j As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
Set rs = db.OpenRecordset("Uren tbv verzamelengineer")
Interval = #12:00:00 AM#
rs.MoveFirst
While Not rs.EOF
If Not IsNull(rs(varFieldName)) Then
Interval = Interval + rs(varFieldName)
End If
rs.MoveNext
Wend
totaaluren = Int(CSng(Interval * 24))
totaalminuten = Int(CSng(Interval * 1440))
uren = totaaluren Mod 24
minuten = totaalminuten Mod 60
TotME = totaaluren & ":" & minuten
ExitProc:
On Error Resume Next
rs.Close
db.Close
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
, "Uren kunnen niet worden getotaliseerd..."
Resume ExitProc
End Function
-------------------------CODE----------------------------------