Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 11th, 2004, 01:26 PM
Registered User
Join Date: Feb 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculate Workdays minus holidays

I have the following code in a module:

Private Sub END_DATE_AfterUpdate()
Dim dif As Integer
Dim i As Integer
Dim dCount As Integer
Dim midTemp

   dCount = 1

   dif = DateDiff("d", START_DATE, END_DATE, vbMonday, vbFirstJan1)
   For i = 1 To dif
       midTemp = DateAdd("d", i, START_DATE)
       If Weekday(midTemp, vbMonday) < 6 Then
            dCount = dCount + 1
        End If
    Next i
NUM_DAYS = dCount
End Sub

I used the code from an existing post(changed accordingly) and it works great. It pulls the Start and End date from my form. Now I would like to be able to have the code subtract out holidays that I determine. Any easy ideas?


Reply With Quote
  #2 (permalink)  
Old February 11th, 2004, 04:17 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG


Clever code...

FYI: the DateAdd and DateDiff functions already have a "w" option (weekday) that counts weekdays already, so no need to use "d" (day) and then pull out weekends manually.

As for holidays, since they vary from worksite to worksite, the easiest thing I can think of is for you to create a holidays table with fields strName, intMonth, and intDay. Omit the year because you want your table to work for reoccuring holidays.

In your code, loop through the table, construct a current holiday

dtmHoliday = DateSerial(Year(Date()), intMonth, intDay)

if it falls between the start and end dates, then subtract it from your total.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
DateDiff to exclude weekends and holidays dbartelt Access 2 April 12th, 2008 05:14 PM
Date diff excluding holidays and weekends Altonjain Classic ASP Professional 0 February 9th, 2006 12:56 AM
Workdays Using DateDiff iancrabtree Access VBA 7 November 26th, 2005 09:46 PM
Access Workdays calculation doug.hall Access 1 April 26th, 2005 02:19 PM
Minus Key in Datagrid whammoed VB.NET 0 September 29th, 2003 09:48 AM

All times are GMT -4. The time now is 11:01 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.