thesuggs76
Board Regular
- Joined
- Nov 15, 2006
- Messages
- 247
Hi All
I am trying to calculate the working days and I have it working when I'm using two set dates, however when I try to use todays date, Date() it doesn't work. I have included the VB code that I'm using. The result is 0. I have created a quere where I used Date() but named it Today.
Any help would be much appreciated
Thanks
Public Function FWaitingTime(Received_Date As Date, Today As Date) As Integer
On Error GoTo Err_FWaitingTime
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays", dbOpenSnapshot)
Received_Date = Received_Date + 1
'To count Received_Date as the 1st day comment out the line above
intCount = 0
Do While Received_Date <= InitialContact_Date
rst.FindFirst "[HolidayDate] = DateValue('" & Received_Date & "')"
If Weekday(Received_Date) <> vbSunday And Weekday(Received_Date) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
Received_Date = Received_Date + 1
Loop
FWaitingTime = intCount
Exit_FWaitingTime:
Exit Function
Err_FWaitingTime:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_FWaitingTime
End Select
End Function
I am trying to calculate the working days and I have it working when I'm using two set dates, however when I try to use todays date, Date() it doesn't work. I have included the VB code that I'm using. The result is 0. I have created a quere where I used Date() but named it Today.
Any help would be much appreciated
Thanks
Public Function FWaitingTime(Received_Date As Date, Today As Date) As Integer
On Error GoTo Err_FWaitingTime
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays", dbOpenSnapshot)
Received_Date = Received_Date + 1
'To count Received_Date as the 1st day comment out the line above
intCount = 0
Do While Received_Date <= InitialContact_Date
rst.FindFirst "[HolidayDate] = DateValue('" & Received_Date & "')"
If Weekday(Received_Date) <> vbSunday And Weekday(Received_Date) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
Received_Date = Received_Date + 1
Loop
FWaitingTime = intCount
Exit_FWaitingTime:
Exit Function
Err_FWaitingTime:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_FWaitingTime
End Select
End Function