Results 1 to 7 of 7
  1. #1
    PeterS is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    45

    Calculating Workdays

    Hi


    I have searched the internet looking for a solution but being new to Access I did not understand most of what I found. There is alot of information on VBA but I do not relly understand it and am not sure exactly to place it in the query.

    I want to calculate the number of working days between two dates.

    My SQL statement is as follows:

    SELECT tblEmployeeID_Pk.First_Name, tblEmployeeID_Pk.Last_Name, tblLeave_Type.Description, tblLeaveCount.Start_Date, tblLeaveCount.Finish_Date, DateDiff("d",[Start_Date],[Finish_Date])+1 AS Workdays
    FROM tblHolidays INNER JOIN (tblLeave_Type INNER JOIN (tblEmployeeID_Pk INNER JOIN tblLeaveCount ON tblEmployeeID_Pk.EmployeeID_Pk = tblLeaveCount.EmployeeID_Fk) ON tblLeave_Type.Leave_TypeID_Pk = tblLeaveCount.Leave_Type_FK) ON tblHolidays.None_Work_DayID_Pk = tblLeave_Type.Leave_TypeID_Pk;

    I get the number of days in the month but I need the number of working days. I have a table called tblHolidays wich includes all the public holidays. Please help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I have a table of tCalDates. It has every date in a calendar.
    qsWorkDays query, pulls all dates that are not 1 nor 7

    format([CalDate],"w") = day of week
    1 = Sun
    7 = Sat

    my query to pull workdays from
    qsWorkDays but not days from tHolidays.

    or qsNoWork query pulls all Sat,Sun, and tHolidays.
    then ignore everything in qsNoWork dates.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    As you discovered, this is a common topic. You will need a VBA procedure. Here is one discussion from this forum with complete code.
    https://www.accessforums.net/showthread.php?t=60074&highlight=workdays

    Search forum on keyword 'workdays' to see more.

    This article shows how to call function in query https://www.techonthenet.com/access/...s/workdays.php
    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.

  4. #4
    PeterS is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    45
    Thanks ranman
    I just want to understand;
    1. You have an existing table called [tCalDates] that you created, containing all the calendar dates with each day from Mon - Sun numbered 1 through 7?

    2. You created a Query called [qsWorkDays] that pulls all the dates excluding 1 (=Sunday) and 7 (=Saturday)

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Select [datefld] ,format([datefld],"w") as DoW from tCalDates

  6. #6
    PeterS is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    45
    Ok thanks guys but I am totally lost and do not understand anything you have said. Please can we start again?

    My SQL statement for the query is as follows;

    SELECT tblEmployee.First_Name, tblEmployee.Last_Name, tblLeave_Type.Description, tblLeaveCount.Start_Date, tblLeaveCount.Finish_Date, DateDiff("d",[Start_Date],[Finish_Date])+1 AS Workdays
    FROM tblHolidays INNER JOIN (tblLeave_Type INNER JOIN (tblEmployee INNER JOIN tblLeaveCount ON tblEmployee.EmployeeID_Pk = tblLeaveCount.EmployeeID_Fk) ON tblLeave_Type.Leave_TypeID_Pk = tblLeaveCount.Leave_Type_FK) ON tblHolidays.None_Work_DayID_Pk = tblLeave_Type.Leave_TypeID_Pk
    WHERE (((tblLeave_Type.Description)="Annual Leave") AND ((tblLeaveCount.Start_Date) Between [Forms]![frmAnnualLeaveDaysCount]![txtStart_Date] And [Forms]![frmAnnualLeaveDaysCount]![txtFinish_Date]));

    I can calculate the number of days between the Start_Date and the Finish_Date quite easily in query design. From there on I am totally lost. Please can you give me a detailed breakdown of what to do? I would really like to learn this stuff but I do not understand any of the things you are answering me with or directing me to go and look at.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    1. create a general module in VBA editor

    2. copy/paste code from the referenced link

    3. test and debug code, modify as needed for your situation

    4. build query referencing the function as described in other link or reference function in textbox on form or report

    If you don't understand any of these steps, I suggest you undertake some tutorials either on-line, with a book, or a formal classroom.
    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.

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

Similar Threads

  1. Calculating Workdays in between two dates
    By Radtastic10 in forum Programming
    Replies: 8
    Last Post: 08-15-2016, 03:09 PM
  2. Can;t get Workdays function to work
    By khughes46 in forum Programming
    Replies: 5
    Last Post: 12-11-2014, 02:07 PM
  3. Workdays Code
    By tomnsd in forum Programming
    Replies: 4
    Last Post: 08-16-2013, 02:30 PM
  4. DateAdd function for workdays?
    By 10 Gauge in forum Programming
    Replies: 2
    Last Post: 04-06-2011, 09:20 AM
  5. Calculating turnaround time on workdays
    By mathonix in forum Queries
    Replies: 1
    Last Post: 04-22-2010, 05:34 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