Calculating Average workdays

R

Risky_Business

Hi
I'm using a funtion to calculate the number of business days between
two dates, see below. This is working fine, however when I try to
calculate the average number of days the number my query returns is way
off. I dumped the data into a table and noticed the numbers in the
table, days between to events, doesn't correspond to the numbers on
data view after I run the query.

Help please

Here is the function

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)

StartDate = StartDate + 1


intCount = 0

Do While StartDate <= EndDate

rst.FindFirst "[HolidayDate] = #" & StartDate & "#"
If Weekday(StartDate) <> vbSunday And Weekday(StartDate) <> vbSaturday
Then
If rst.NoMatch Then intCount = intCount + 1
End If

StartDate = StartDate + 1

Loop

WorkingDays2 = intCount

Exit_WorkingDays2:
Exit Function

Err_WorkingDays2:
Select Case Err

Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select

End Function

Here is the query I use to call the functions

SELECT Trane.date, WorkingDays2([qry_Date Req
GBAS]![TRANS_YYYYMMDD],[Trane]![date]) AS Days
FROM Trane INNER JOIN [qry_Date Req GBAS] ON (Trane.case = [qry_Date
Req GBAS].CASE_NUM) AND (Trane.cert = [qry_Date Req GBAS].CERT_NUM) AND
(Trane.clmt = [qry_Date Req GBAS].CLMT_NUM);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top