Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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?

Thanks.

Dan
 
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
Default

Dan,

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




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





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