About a year ago, I found this function which I believe was originally posted by MichaelRed(it's a great function!).
It counts the days between StartDate and EndDate while excluding weekends and Holidays (excludes Holidays by referencing the tblHolidays table which includes a date field called Holidate).
Public Function DeltaDays(StartDate As Date, EndDate As Date) As Integer
'Get the number of workdays between the given dates
Dim dbs As Database
Dim rstHolidays 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("tblHolidays", dbOpenDynaset)
NumSgn = Chr(35)
MyDate = Format(StartDate, "Short Date"
For Idx = CLng(StartDate) To CLng(EndDate)
Select Case (WeekDay(MyDate))
Case Is = 1 'Sunday
'Do Nothing, it is NOT a Workday
Case Is = 7 'Saturday
'Do Nothing, it is NOT a Workday
Case Else 'Normal Workday
strCriteria = "[HoliDate] = " & NumSgn & MyDate & NumSgn
rstHolidays.FindFirst strCriteria
If (rstHolidays.NoMatch) Then
NumDays = NumDays + 1
Else
'Do Nothing, it is NOT a Workday
End If
End Select
MyDate = DateAdd("d", 1, MyDate)
Next Idx
DeltaDays = NumDays
End Function
Anyway, this works great but I think I might be asking too much of it.
I have an application in Access 97.
This application has close to 10,000 records.
Each record relates to a request that needs to be completed.
Every one of those records(requests)has 3 date fields:
ReceiptDate - When the request was keyed in
PendingDate - The last time somebody did work on the request.
ClosedDate - When the request was completed.
(Just in case it's helpful, the UID field name is Tracking#)
Here's the SQL statement from one of the queries I use:
SELECT tLog.Coordinator, tLog.Tracking#, tLog.ReceiptDate, tLog.State, tLog.RequestType, tLog.ClosureDate, tLog.PendingDate, DeltaDays([ReceiptDate],Date()) AS TotalDaysOpen, DeltaDays([PendingDate],Date()) AS PendingTillClosed
FROM tLog
WHERE (((tLog.ClosureDate) Is Null));
It doesn't take long to run, but if I try to send it to Excel or put it behind a report in Access, it takes at least five minutes.
My machine specs are:
1.4 Ghz processor
256 M RAM
So now I have two questions:
1. In this scenario, does indexing the date fields even make a difference?(I know I'm reaching here, I'm desperate)
2. Is there anything that would help speed up the process?
Sorry if I glazed over anything that would help.
Let me know if I did.
Thanks in Advance.
Chris
It counts the days between StartDate and EndDate while excluding weekends and Holidays (excludes Holidays by referencing the tblHolidays table which includes a date field called Holidate).
Public Function DeltaDays(StartDate As Date, EndDate As Date) As Integer
'Get the number of workdays between the given dates
Dim dbs As Database
Dim rstHolidays 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("tblHolidays", dbOpenDynaset)
NumSgn = Chr(35)
MyDate = Format(StartDate, "Short Date"
For Idx = CLng(StartDate) To CLng(EndDate)
Select Case (WeekDay(MyDate))
Case Is = 1 'Sunday
'Do Nothing, it is NOT a Workday
Case Is = 7 'Saturday
'Do Nothing, it is NOT a Workday
Case Else 'Normal Workday
strCriteria = "[HoliDate] = " & NumSgn & MyDate & NumSgn
rstHolidays.FindFirst strCriteria
If (rstHolidays.NoMatch) Then
NumDays = NumDays + 1
Else
'Do Nothing, it is NOT a Workday
End If
End Select
MyDate = DateAdd("d", 1, MyDate)
Next Idx
DeltaDays = NumDays
End Function
Anyway, this works great but I think I might be asking too much of it.
I have an application in Access 97.
This application has close to 10,000 records.
Each record relates to a request that needs to be completed.
Every one of those records(requests)has 3 date fields:
ReceiptDate - When the request was keyed in
PendingDate - The last time somebody did work on the request.
ClosedDate - When the request was completed.
(Just in case it's helpful, the UID field name is Tracking#)
Here's the SQL statement from one of the queries I use:
SELECT tLog.Coordinator, tLog.Tracking#, tLog.ReceiptDate, tLog.State, tLog.RequestType, tLog.ClosureDate, tLog.PendingDate, DeltaDays([ReceiptDate],Date()) AS TotalDaysOpen, DeltaDays([PendingDate],Date()) AS PendingTillClosed
FROM tLog
WHERE (((tLog.ClosureDate) Is Null));
It doesn't take long to run, but if I try to send it to Excel or put it behind a report in Access, it takes at least five minutes.
My machine specs are:
1.4 Ghz processor
256 M RAM
So now I have two questions:
1. In this scenario, does indexing the date fields even make a difference?(I know I'm reaching here, I'm desperate)
2. Is there anything that would help speed up the process?
Sorry if I glazed over anything that would help.
Let me know if I did.
Thanks in Advance.
Chris