thisisntwally
12-10-2007, 04:43 AM
i've been away from access and my database for a month or two, and upon my return I've found myself a little baffled.
I've got a date validation in a form as so:
If ((vFrm!txtSSD - vFrm!txtDOR) > 3 And Nz(vFrm!txtComments, "") = "") Then
MsgBox "Turnaround Time is greater than 3 days, please comment."
amdValid = False
End If
but i only want to count weekdays. I've found a few examples searching datediff and weekdays, but I'm kinda lost on how to integrate the two. This is probably because I don't exactly understand how the following code is working. I think i need to call the workingdays() in place of vFrm!txtSSD - vFrm!txtDOR and call txtssd and txtdor as the start and end dates within the workingdays function, but I'm not exactly sure. Could anyone confirm/disconfirm this, or usher me along another road?
Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
On Error GoTo Err_WorkingDays
Dim intCount As Integer
StartDate = StartDate + 1
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
WorkingDays = intCount
Exit_WorkingDays:
Exit Function
Err_WorkingDays:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays
End Select
End Function
I've got a date validation in a form as so:
If ((vFrm!txtSSD - vFrm!txtDOR) > 3 And Nz(vFrm!txtComments, "") = "") Then
MsgBox "Turnaround Time is greater than 3 days, please comment."
amdValid = False
End If
but i only want to count weekdays. I've found a few examples searching datediff and weekdays, but I'm kinda lost on how to integrate the two. This is probably because I don't exactly understand how the following code is working. I think i need to call the workingdays() in place of vFrm!txtSSD - vFrm!txtDOR and call txtssd and txtdor as the start and end dates within the workingdays function, but I'm not exactly sure. Could anyone confirm/disconfirm this, or usher me along another road?
Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
On Error GoTo Err_WorkingDays
Dim intCount As Integer
StartDate = StartDate + 1
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
WorkingDays = intCount
Exit_WorkingDays:
Exit Function
Err_WorkingDays:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays
End Select
End Function