
Originally Posted by
ItsMe
What changes did you make? Can you post the code? Please use the Go Advanced option when posting here in the forum. There is a tool there that you can use to wrap code in Tags to preserve formatting (#).
I've changed the input value for the Query so that it reads Networkinghours(([Replacement Event]![Date/Time Start Rebuild],[Replacement Event]![Date/Time Complete Rebuild])/60). I am not sure how to put the changes you suggested into the code so that it can run.
Here is the code:
Code:
Option Compare Database
Public Function NetWorkhours(dteStart As Date, dteEnd As Date) As Single
Dim intGrossDays As Integer
Dim intGrossHours As Single
Dim dteCurrDate As Date
Dim i As Integer
Dim WorkDayStart As Date
Dim WorkDayend As Date
Dim nonWorkDays As Integer
Dim StartDayhours As Single
Dim EndDayhours As Single
NetWorkhours = 0
nonWorkDays = 0
'Calculate work day hours on 1st and last day
WorkDayStart = DateValue(Rebuild_Start_Date_Time) + TimeValue("06:00am")
WorkDayend = DateValue(Rebuild_Complete_Date_Time) + TimeValue("02:00pm")
StartDayhours = DateDiff("n", Rebuild_Start_Date_Time, WorkDayend)
EndDayhours = DateDiff("n", WorkDayStart, Rebuild_Complete_Date_Time)
'adjust for time entries outside of business hours
If StartDayhours < 0 Then
StartDayhours = 0
End If
If EndDayhours > 8 Then
EndDayhours = 8
End If
'Calculate total hours and days between start and end times
intGrossDays = DateDiff("d", Rebuild_Start_Date_Time, Rebuild_Complete_Date_Time)
intGrossHours = DateDiff("n", Rebuild_Start_Date_Time, Rebuild_Complete_Date_Time)
'count number of weekend days and holidays (from a table called "Holidays" that lists them)
For i = 0 To intGrossDays
dteCurrDate = dteStart + i
If Weekday(dteCurrDate, vbSaturday) < 3 Then
nonWorkDays = nonWorkDays + 1
Else
If Not IsNull(DLookup("[HolDate]", "Holidays", "[HolDate] = #" & Int(dteCurrDate) & "#")) Then
nonWorkDays = nonWorkDays + 1
End If
End If
Next i
'Calculate number of work hours
Select Case intGrossDays
Case 0
'start and end time on same day
NetWorkhours = intGrossHours
Case 1
'start and end time on consecutive days
NetWorkhours = NetWorkhours + StartDayhours
NetWorkhours = NetWorkhours + EndDayhours
Case Is > 1
'start and end time on non consecutive days
NetWorkhours = NetWorkhours - (nonWorkDays * 1)
NetWorkhours = (intGrossDays - 1 - nonWorkDays) * 8
NetWorkhours = NetWorkhours + StartDayhours
NetWorkhours = NetWorkhours + EndDayhours
End Select
End Function