Me.[Text25] = GetBusinessDay([Due_Date] - [Result_Date] was my attempt, but it doesn't calculate a date.
Option Compare Database
Function GetBusinessDay(datStart As Date, intDayAdd As Integer)
On Error GoTo Error_Handler
Dim rst As DAO.Recordset
Dim DB As DAO.Database
'Dim strSQL As String
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHoliday2014", dbOpenSnapshot)
If intDayAdd > 0 Then
Do While intDayAdd > 0
datStart = datStart + 1
rst.FindFirst "[HolidayDate] = #" & datStart & "#"
If Weekday(datStart) <> vbSunday And Weekday(datStart) <> vbSaturday Then
If rst.NoMatch Then intDayAdd = intDayAdd - 1
End If
Loop
ElseIf intDayAdd < 0 Then
Do While intDayAdd < 0
datStart = datStart - 1
rst.FindFirst "[HolidayDate] = #" & datStart & "#"
If Weekday(datStart) <> vbSunday And Weekday(datStart) <> vbSaturday Then
If rst.NoMatch Then intDayAdd = intDayAdd + 1
End If
Loop
End If
GetBusinessDay = datStart
Exit_Here:
rst.Close
Set rst = Nothing
Set DB = Nothing
Exit Function
Error_Handler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Here
End Function
Private Sub Result_Date_AfterUpdate()
Me.[TAT] = GetBusinessDay([Due_Date] - [Result_Date], 0)
End Sub
Function GetBusinessDay(datStart As Date, intDayAdd As Integer)
Option Compare Database
Public Function fGetWorkdays2(pstart As Date, pend As Date) As Integer
fGetWorkdays2 = 7 - Weekday(pstart) + 5 * (DateDiff("ww", pstart, pend) - 1) + Weekday(pend) - 1
End Function
Private Sub Result_Date_AfterUpdate()
Me.[TAT] = fGetWorkdays2([Due_Date] - [Result_Date], 0)
End Sub
fGetWorkdays2 = 7 - Weekday(pstart) + 5 * (DateDiff("ww", pstart, pend) - 1) + Weekday(pend) - 1
ret=0
' return value, holds weekdays between pstart and pend
ret =7 - Weekday(pstart)
' notes about what this line is doing
ret = ret + 5 * (DateDiff("ww", pstart, pend) - 1)
' notes about what this line does
ret = ret + Weekday(pend) - 1
' notes about what this line did
fGetWorkdays2 = ret
Public Function fGetWorkdays2(pstart As Date, pend As Date) As Integer
ret=0
' return value, holds weekdays between pstart and pend
ret =7 - Weekday(pstart)
' notes about what this line is doing [B](defines start as Monday-Sunday)[/B]
ret = ret + 5 * (DateDiff("ww", pstart, pend) - 1)
' notes about what this line does [B](Only count Monday - Friday)[/B]
ret = ret + Weekday(pend) - 1
' notes about what this line did [B](check to see i date is a sat or sun)[/B]
fGetWorkdays2 = ret
End Function
Public Function fGetWorkdays2(pstart As Date, pend As Date) As Integer
ret=0
' return value, holds weekdays between pstart and pend
ret =7 - Weekday(pstart)
' notes about what this line is doing (defines start as Monday-Sunday)
ret = ret + 5 * (DateDiff("ww", pstart, pend) - 1)
' notes about what this line does (only count Monday - Friday)
ret = ret + Weekday(pend) - 1
' notes about what this line did (check to see if date is a sat or sun)
fGetWorkdays2 = ret
End Function
Dim LTotal as Long
LTotal = DCount("HolidayDate","tblHoliday2014")
pstart = Ret - LTotal
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
Private Sub Result_Date_AfterUpdate()
Me.[TAT] = Weekdays([Due_Date] - [Result_Date], 0)
End Sub
' Count the number of holidays.
Dim nHoliday As Intager
nHolidays = DCount(Expr:="[Holiday]", _
Domain:=strHolidays, _
Criteria:=strWhere)
Weekdays = nWeekdays - nHolidays
Weekdays_Exit:
Exit Function
Weekdays_Error:
Weekdays = -1
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Weekdays"
Resume Weekdays_Exit
Weekdays(ByRef startDate As Date, _
ByRef endDate As Date _
) As Integer
...
...
...
Me.[TAT] = Weekdays([Due_Date] - [Result_Date], 0)
Public Function get_Weekdays(ByRef startDate As Date, ByRef endDate As Date) As Integer
ret = 0
' return value of function, 0 by default
get_Weekdays=ret
End Function
Public Function get_Weekdays(ByRef startDate As Date, ByRef endDate As Date) As Integer
ret = 0
' return value of function, 0 by default
get_Weekdays = ret
End Function
Private Sub Result_Date_AfterUpdate()
Me.[TAT] = get_Weekdays([Due_Date] - [Result_Date], 0)
End Sub
Public Function get_Weekdays(pstart As Date, pend As Date) As Integer
ret=0
' return value, holds weekdays between pstart and pend
ret =7 - Weekday(pstart)
' notes about what this line is doing (defines start as Monday-Sunday)
ret = ret + 5 * (DateDiff("ww", pstart, pend) - 1)
' notes about what this line does (only count Monday - Friday)
ret = ret + Weekday(pend) - 1
' notes about what this line did (check to see if date is a sat or sun)
get_Weekdays = ret
End Function
Private Sub Result_Date_AfterUpdate()
Dim Due_Date As String
Dim Result_Date As String
Int(NZ(Me.Due_Date))
Int(NZ(Me.Result_Date))
Me.[TAT] = get_Weekdays([Due_Date] - [Result_Date], 0)
End Sub