I have an access form that calculates workdays excluding holidays keyed in a tabe, and weekends. When I put a date in 2011 it does not take into account the holidays. I am new at this and actually got this from the internet. Can someone please adjust the code so it takes into account dates in 2011 and future. Thanks
Option Compare Database
Option Explicit
Dim Response, Title, Prompt As String
Private Sub Form_Current()
TotalDaysBetweenStartStop = Null
TotalWorkDaysBetweenStartStop = Null
StartDate = Null
EndDate = Null
End Sub
Private Sub StartDate_AfterUpdate()
If IsNull(EndDate) Then
TotalDaysBetweenStartStop = Null
TotalWorkDaysBetweenStartStop = Null
DoCmd.GoToControl "EndDate"
ElseIf Not IsNull(EndDate) Then
CalculateWorkdays
End If
End Sub
Private Sub EndDate_AfterUpdate()
If IsNull(StartDate) Then
TotalDaysBetweenStartStop = Null
TotalWorkDaysBetweenStartStop = Null
DoCmd.GoToControl "StartDate"
Else
CalculateWorkdays
End If
End Sub
Private Sub CalculateWorkdays()
Dim TempDate As Date, WorkDays As Integer, Counter As Integer, AllDays As Integer
If IsNull(StartDate) Or IsNull(EndDate) Then ' ------------------ Check for Legitimate Dates?
Prompt = "Enter a Legitimate Start Date and End Date"
Title = "Invalid Date"
Exit Sub
End If
'*********** ************************************* Calculate ALL Days between StartDate and EndDate
AllDays = DateDiff("d", StartDate, EndDate)
TotalDaysBetweenStartStop = AllDays
'************************************************ Calculate WORK Days between StartDate and EndDate
WorkDays = 0
For Counter = 0 To AllDays
TempDate = StartDate + Counter
If IsNull(DLookup("[HolidayDate]", "tblHolidays", "HolidayDate = #" & TempDate & "#")) _
And WeekDay(TempDate) <> 7 _
And WeekDay(TempDate) <> 1 Then
WorkDays = WorkDays + 1
End If
Next Counter
TotalWorkDaysBetweenStartStop = WorkDays
End Sub
Option Compare Database
Option Explicit
Dim Response, Title, Prompt As String
Private Sub Form_Current()
TotalDaysBetweenStartStop = Null
TotalWorkDaysBetweenStartStop = Null
StartDate = Null
EndDate = Null
End Sub
Private Sub StartDate_AfterUpdate()
If IsNull(EndDate) Then
TotalDaysBetweenStartStop = Null
TotalWorkDaysBetweenStartStop = Null
DoCmd.GoToControl "EndDate"
ElseIf Not IsNull(EndDate) Then
CalculateWorkdays
End If
End Sub
Private Sub EndDate_AfterUpdate()
If IsNull(StartDate) Then
TotalDaysBetweenStartStop = Null
TotalWorkDaysBetweenStartStop = Null
DoCmd.GoToControl "StartDate"
Else
CalculateWorkdays
End If
End Sub
Private Sub CalculateWorkdays()
Dim TempDate As Date, WorkDays As Integer, Counter As Integer, AllDays As Integer
If IsNull(StartDate) Or IsNull(EndDate) Then ' ------------------ Check for Legitimate Dates?
Prompt = "Enter a Legitimate Start Date and End Date"
Title = "Invalid Date"
Exit Sub
End If
'*********** ************************************* Calculate ALL Days between StartDate and EndDate
AllDays = DateDiff("d", StartDate, EndDate)
TotalDaysBetweenStartStop = AllDays
'************************************************ Calculate WORK Days between StartDate and EndDate
WorkDays = 0
For Counter = 0 To AllDays
TempDate = StartDate + Counter
If IsNull(DLookup("[HolidayDate]", "tblHolidays", "HolidayDate = #" & TempDate & "#")) _
And WeekDay(TempDate) <> 7 _
And WeekDay(TempDate) <> 1 Then
WorkDays = WorkDays + 1
End If
Next Counter
TotalWorkDaysBetweenStartStop = WorkDays
End Sub