标题: 请教这个计算工作日的函数有何不对 [打印本页] 作者: sarfeilee 时间: 2008-3-24 15:13 标题: 请教这个计算工作日的函数有何不对 Public Function NetWorkDays(StartDate As Date, EndDate As Date) As Integer
Dim dbs As Database
Dim rstHolidays As Recordset
Dim rstAddiWorkingDay As Recordset
Dim Idx As Long
Dim MyDate As Date
Dim NumDays As Long
Dim strCriteria As String
Dim NumSgn As String * 1
Set dbs = CurrentDb
Set rstHolidays = dbs.OpenRecordset("Holidays", dbOpenDynaset)
Set rstAddiWorkingDay = dbs.OpenRecordset("AdditionalWorkingDay", dbOpenDynaset)
NumSgn = Chr(35)
If EndDate >= StartDate Then
MyDate = Format(StartDate, "Short Date")
For Idx = CLng(StartDate) To CLng(EndDate)
Select Case (Weekday(MyDate))
Case Is = 1 'Sunday
strCriteria = "[AdditionalWorkingDay] = " & NumSgn & Format$(MyDate, "yyyy-mm-dd") & NumSgn
rstAddiWorkingDay.FindFirst strCriteria
If (rstHolidays.NoMatch) Then
Else
NumDays = NumDays + 1
End If
Case Is = 7 'Saturday
strCriteria = "[AdditionalWorkingDay] = " & NumSgn & Format$(MyDate, "yyyy-mm-dd") & NumSgn
rstAddiWorkingDay.FindFirst strCriteria
If (rstAddiWorkingDay.NoMatch) Then
Else
NumDays = NumDays + 1
End If
Case Else 'Normal Workday