Code:
Private Sub Form_Open(Cancel As Integer)
Me.TAT = WorkingDays(Due_Date, Result_Date)
End Sub
When I open the form I get a You can't assign a value to this object.
I have a function, that excludes weekends and holidays from a calculation. Thanks
VB
Code:
Option Compare Database
Option Explicit
Public Function WorkingDays(Due_Date As Date, Result_Date As Date) As Integer
'-- Return the number of WorkingDays between Due_Date and Result_Date
On Error GoTo err_workingDays
Dim intCount As Integer
If IsDate(Due_Date) And IsDate(Result_Date) Then
If Result_Date >= Due_Date Then
intCount = 0
Do While Due_Date < Result_Date
Due_Date = Due_Date + 1
'-- Holiday code
If Weekday(Due_Date, vbMonday) <= 5 And _
IsNull(DLookup("[Description]", "Holidays", _
"[Holiday] = " & Format(Due_Date, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then: intCount = intCount + 1
Loop
WorkingDays = intCount
Else
WorkingDays = -1 '-- To show an error
End If
Else
WorkingDays = -1 '-- To show an error
End If
exit_workingDays:
Exit Function
err_workingDays:
MsgBox "Error No: " & Err.Number & vbCr & _
"Description: " & Err.Description
Resume exit_workingDays
End Function