Results 1 to 2 of 2
  1. #1
    jsiketa is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    1

    Question Calculating Networkdays

    Hi, I have used the below WorkingDays function to calculate the number of weekdays between two dates (excluding holidays referenced from a table called tblHolidays). It appears the function does not always calculate the days correctly and is out by a day. Is there a way of full proofing this?
    ______________________________________

    Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
    '................................................. ...................
    ' Name: WorkingDays
    ' Inputs: StartDate As Date
    ' EndDate As Date
    ' Returns: Integer
    ' Author: Arvin Meyer
    ' Date: May 5,2002
    ' Comment: Accepts two dates and returns the number of weekdays between them
    ' Note that this function has been modified to account for holidays. It requires a table
    ' named tblHolidays with a field named HolidayDate.
    '................................................. ...................
    On Error GoTo Err_WorkingDays

    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
    'To count StartDate as the 1st day comment out the line above

    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

    WorkingDays = intCount

    Exit_WorkingDays:
    Exit Function

    Err_WorkingDays:
    Select Case Err

    Case Else
    MsgBox Err.Description
    Resume Exit_WorkingDays
    End Select

    End Function

    '*********** Code End **************

  2. #2
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Search the Internet, I've seen this algorithm before.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculating Dates
    By TC0126 in forum Queries
    Replies: 1
    Last Post: 02-23-2010, 08:13 PM
  2. Calculating the column value
    By access in forum Queries
    Replies: 6
    Last Post: 08-20-2009, 11:51 AM
  3. Calculating the sum of every four records.
    By Alanlives in forum Queries
    Replies: 0
    Last Post: 07-31-2009, 05:56 AM
  4. Calculating Dates
    By AJ0424 in forum Programming
    Replies: 1
    Last Post: 07-14-2009, 08:29 AM
  5. Calculating Values
    By Jahan in forum Queries
    Replies: 1
    Last Post: 07-09-2006, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums