Results 1 to 6 of 6
  1. #1
    DHook is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2014
    Posts
    3

    Weekend/Holiday Exclusion:

    Hello -

    I am trying to write a query in which Weekends and Holidays are excluded. I understand that Access 2007 does not have the ability to exclude w/e, holidays; but I have a found a VBA function (shown below); however, when I run the Compile:debug I get an error in the string (nWeekdays = Weekdays(startDate, endDate))


    The below stems from the site; http://msdn.microsoft.com/en-us/libr...ice.12%29.aspx.
    I've created the Holiday table in the string as well but cant seem to get past the error.

    Any help is appreciated. Thank you.

    Public Function Workdays(ByRef startDate As Date, _
    ByRef endDate As Date, _
    Optional ByRef strHolidays As String = "Holidays" _
    ) As Integer
    ' Returns the number of workdays between startDate
    ' and endDate inclusive. Workdays excludes weekends and
    ' holidays. Optionally, pass this function the name of a table
    ' or query as the third argument. If you don't the default
    ' is "Holidays".
    On Error GoTo Workdays_Error
    Dim nWeekdays As Integer
    Dim nHolidays As Integer
    Dim strWhere As String

    ' DateValue returns the date part only.
    startDate = DateValue(startDate)
    endDate = DateValue(endDate)

    nWeekdays = Weekdays(startDate, endDate)

    If nWeekdays = -1 Then
    Workdays = -1
    GoTo Workdays_Exit
    End If

    strWhere = "[Holiday] >= #" & startDate _
    & "# AND [Holiday] <= #" & endDate & "#"

    ' Count the number of holidays.
    nHolidays = DCount(Expr:="[Holiday]", _
    Domain:=strHolidays, _
    Criteria:=strWhere)

    Workdays = nWeekdays - nHolidays

    Workdays_Exit:
    Exit Function

    Workdays_Error:
    Workdays = -1
    MsgBox "Error " & Err.Number & ": " & Err.Description, _
    vbCritical, "Workdays"
    Resume Workdays_Exit

    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Did you copy in the second function in that link? That line is calling it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DHook is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2014
    Posts
    3
    Ok, so I've included the Weekdays script in the Module; and it now compiles:debugs, but when I run the actual query in access I get an error... Undefined Function.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The module doesn't have the same name, does it? Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    DHook is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2014
    Posts
    3
    Thanks for the help; I cannot post the db due to Hipaa data; I actually got the DateDiff results w/ exclusion of w/e and Holidays figured out, but I am now in need of the calculation of future dates with w/e and holidays excluded; Exp: (ReceivedDate+1)... I know, sorry.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You may find the iso_Workday... function here to be of value.
    The dialog in the text is good too.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-23-2014, 07:50 AM
  2. weekdays versus weekend
    By webisti in forum Access
    Replies: 6
    Last Post: 09-10-2013, 02:27 AM
  3. how do I not record date of the weekend or holiday?
    By fabiobarreto10 in forum Forms
    Replies: 4
    Last Post: 06-12-2012, 09:33 AM
  4. Payslip Holiday Pay design
    By crxftw in forum Access
    Replies: 5
    Last Post: 07-22-2011, 11:58 AM
  5. function for national holiday
    By barkarlo in forum Access
    Replies: 0
    Last Post: 12-18-2006, 03:39 PM

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