Calculate Workdays in Microsoft Access Excluding Weekends and Holidays
Question details
Calculate working days between two dates in an Access query, excluding weekends and holidays stored in a separate table.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- An Access database uses a VBA function and a holiday table to calculate working days between start and end dates.
- Observed behavior
- The existing VBA function has syntax and expression errors that prevent the calculation from working correctly.
Confirm the names of your holiday table and date field, and make sure the start and end dates contain valid, non-null dates. The example below uses a table named Holidays and a Date/Time field named HolidayDate.
Create a Workdays function and use it in an Access query
Use a public VBA function to count weekdays while excluding dates found in the holiday table.
This example counts both the start and end dates when they are working days. It excludes Saturday and Sunday, ignores duplicate holiday entries, and raises an error if the end date is earlier than the start date.
In Access, select Create > Module. In the VBA editor, paste the function below into the standard module. Change Holidays and HolidayDate in the DCount expression if your table or field has a different name.
Paste this code: Public Function Workdays(startDate As Date, endDate As Date) As Long Dim d As Date Dim total As Long If DateValue(endDate) < DateValue(startDate) Then Err.Raise vbObjectError + 1000, "Workdays", "End date must not precede start date." End If d = DateValue(startDate) Do While d <= DateValue(endDate) If Weekday(d, vbMonday) <= 5 Then If DCount("*", "[Holidays]", "[HolidayDate] >= #" & Format$(d, "mm\/dd\/yyyy") & "# AND [HolidayDate] < #" & Format$(DateAdd("d", 1, d), "mm\/dd\/yyyy") & "#") = 0 Then total = total + 1 End If End If d = DateAdd("d", 1, d) Loop Workdays = total End Function
In the VBA editor, select Debug > Compile to identify syntax errors. Save the module with a name other than Workdays, such as modDateFunctions.
Open your query in Design View and enter Difference: Workdays([startDate],[endDate]) in an empty Field cell. Replace the field names if needed, then select Run to view the calculated column.

Correct syntax errors in an existing Access VBA function
Use this approach if you already have a function that implements the holiday and weekend rules you need.
Calculate Workdays in a WPS Spreadsheet
WPS Office is a free, lightweight alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move spreadsheet work. It does not fix or run the Access database function; use WPS Spreadsheets for a separate spreadsheet-based calculation.

Frequently Asked Questions
How do I call the Workdays function in an Access query?
In query Design View, enter Difference: Workdays([startDate],[endDate]) in an empty Field cell. Use your actual date field names and ensure the function is Public in a standard module.
Does the function include the start and end dates?
Yes. The example counts each endpoint if it is a weekday and is not listed in the holiday table.
What happens if a holiday falls on a weekend?
The example skips weekends before checking the holiday table, so a weekend holiday is not subtracted a second time.
Why does Access report an undefined Workdays function?
Check that the function is declared Public in a standard module, that the module is not named Workdays, and that Debug > Compile completes without errors.
Can the function handle blank dates?
The example expects valid, non-null start and end dates. Filter out records with blank dates in the query or modify the function to handle Null values before calling it.




