F
Fay
My form contains these fields:
Number (Autonumber)
FirstName (Text)
StartDate (Date)
EndDate (Date)
Holidays (Number)
I want to calculate the number of days inbetween and including StartDate and
EndDate—excluding any Saturdays and Sundays.
This is my standard module.
Public Sub CalculateNoHolidays()
On Error GoTo Err_Holidays
Dim intCount As Integer
Dim Holidays As Integer
'StartDate = StartDate + 1
'If you want to count the day of StartDate as the 1st day
'Comment out the line above
intCount = 0
Do While StartDate <= EndDate
'Make the above < and not <= to not count the EndDate
Select Case Weekday(StartDate)
Case Is = 1, 7
intCount = intCount
Case Is = 2, 3, 4, 5, 6
intCount = intCount + 1
End Select
StartDate = StartDate + 1
Loop
Holidays = intCount
Exit_Holidays:
Exit Sub
Err_Holidays:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_Holidays
End Select
This is the code I created for the EndDate field in AfterUpDate. It is
supposed to call up the standard procedure.
Private Sub EndDate_AfterUpdate()
CalculateNoHolidays
End Sub
I set a breakpoint at Private Sub EndDate_AfterUpdate() to test the code.
What happens is that when it switches over to the standard module, it looks
at the first date—goes back to the Do While StartDate <= EndDate and then
goes out of the loop to Holidays = intCount Holidays show as a zero.
What is wrong?
Please be patient—I am just starting to learn VBA—I am a senior—don’t use
big technical words. Thank you.
Number (Autonumber)
FirstName (Text)
StartDate (Date)
EndDate (Date)
Holidays (Number)
I want to calculate the number of days inbetween and including StartDate and
EndDate—excluding any Saturdays and Sundays.
This is my standard module.
Public Sub CalculateNoHolidays()
On Error GoTo Err_Holidays
Dim intCount As Integer
Dim Holidays As Integer
'StartDate = StartDate + 1
'If you want to count the day of StartDate as the 1st day
'Comment out the line above
intCount = 0
Do While StartDate <= EndDate
'Make the above < and not <= to not count the EndDate
Select Case Weekday(StartDate)
Case Is = 1, 7
intCount = intCount
Case Is = 2, 3, 4, 5, 6
intCount = intCount + 1
End Select
StartDate = StartDate + 1
Loop
Holidays = intCount
Exit_Holidays:
Exit Sub
Err_Holidays:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_Holidays
End Select
This is the code I created for the EndDate field in AfterUpDate. It is
supposed to call up the standard procedure.
Private Sub EndDate_AfterUpdate()
CalculateNoHolidays
End Sub
I set a breakpoint at Private Sub EndDate_AfterUpdate() to test the code.
What happens is that when it switches over to the standard module, it looks
at the first date—goes back to the Do While StartDate <= EndDate and then
goes out of the loop to Holidays = intCount Holidays show as a zero.
What is wrong?
Please be patient—I am just starting to learn VBA—I am a senior—don’t use
big technical words. Thank you.