matthewnsarah07
Registered User.
- Local time
- Today, 04:24
- Joined
- Feb 19, 2008
- Messages
- 192
I have a form for calculating working hours with TOILDate as Date, TimeStart as Date and Time Finish as Date
To allow for night shifts, where TimeFinish is less than TimeStart the following vb is used :
This basically creates two value like 13/12/2010 12:00 (adding a day to the finish time) then performs a datediff and finally strings the two values to fit in a DateTime field.
This works fine except when it get an error number which produces a runtime -###### - how can I stop the errors occuring as this code functions otherwise??
To allow for night shifts, where TimeFinish is less than TimeStart the following vb is used :
Code:
'Night Shift Fix - Test'
Private Sub Command91_Click()
If Me.TimeFinish < Me.TimeStart Then
Dim StartTime As Date
Dim EndTime As Date
Dim EndDate As Date
Dim DiffHour As Integer
Dim DiffMin As Integer
EndDate = Me.TOILDate + 1
StartTime = Me.TOILDate & " " & Me.TimeStart
EndTime = EndDate & " " & Me.TimeFinish
DiffHour = DateDiff("h", [StartTime], [EndTime])
DiffMin = DateDiff("n", [StartTime], [EndTime]) - (DateDiff("h", [StartTime], [EndTime]) * 60)
Me.TotalAdd = [DiffHour] & ":" & [DiffMin]
Me.TotalMultiple = (Me.TotalAdd * 1.5)
Else
End If
End Sub
This basically creates two value like 13/12/2010 12:00 (adding a day to the finish time) then performs a datediff and finally strings the two values to fit in a DateTime field.
This works fine except when it get an error number which produces a runtime -###### - how can I stop the errors occuring as this code functions otherwise??