Results 1 to 7 of 7
  1. #1
    vbagwell1967 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    13

    Adding Holidays back in

    I have everything in my project working except Holidays. Can someone please tell me what is wrong with the following code - I got it off this site. Some wonderful guy helped me out.

    Public Function fCalcWorkingDays_DAssgn(DAssignDate As Date, DCompleteDate As Date) As Integer
    Dim intCountDAssn As Integer

    intCountDAssn = 0

    Do While DAssignDate < DCompleteDate
    Select Case Weekday(DAssignDate)
    Case Is = 1, 7
    intCountDAssn = intCountDAssn + 0
    Case Is = 2, 3, 4, 5, 6
    If DCount("*", "dbo_tblHOLIDAYS", "[Holiday_Date] = #" & DAssignDate & "#") = 0 Then
    intCountDAssn = intCountDAssn + 1
    End If
    End Select
    DAssignDate = DAssignDate + 1
    Loop
    fCalcWorkingDays_DAssgn = intCountDAssn


    End Function

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    What happens when you run the code? Error message, wrong results, nothing? What do you want to happen?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    vbagwell1967 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    13
    It sees the weekends and omits them. It does nothing with the Holidays, no error message. I need for it to exclude Holidays as well.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    The function works for me. Holidays excluded.

    However, it also does not count the completion date even if it is a weekday. If you want to count the completion date then use <=.

    Do While DAssignDate <= DCompleteDate

    Debug your code. Set breakpoint and step execute.

    Holiday_Date is a date/time type field? You use U.S. date format?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    vbagwell1967 is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    13
    Watch : : DCount("*", "dbo_tblHOLIDAYS", "[Holiday_Date] = #" & DAssignDate & "#") : <Out of context> : Variant/Empty : CountDays_Design.fCalcWorkingDays_DAssgn is the message I am getting. I am looking up the "out of context"

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    First time I've ever tried to use Watch. I get the same info, however, the function returns correct result. I've always just used breakpoints and Debug statements.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The VALUE "<Out of context>" is typical for any watch expression when/if the code is not executing.

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

Similar Threads

  1. DateAdd to add back weekends and holidays
    By vbagwell1967 in forum Queries
    Replies: 4
    Last Post: 06-20-2017, 07:38 PM
  2. Allow for holidays
    By msmithtlh in forum Programming
    Replies: 5
    Last Post: 04-10-2014, 04:25 PM
  3. Problems With Adding Data Back To Table
    By jimbob90 in forum Access
    Replies: 10
    Last Post: 09-30-2012, 05:28 PM
  4. Replies: 4
    Last Post: 05-21-2012, 08:21 AM
  5. Replies: 1
    Last Post: 05-22-2010, 08:30 PM

Tags for this Thread

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