VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Access Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Closed Thread
 
Thread Tools Display Modes
Old 07-23-2004, 05:43 AM   #1
babsc01
 
babsc01's Avatar

 
Joined: Jun 2004
Posts: 53
Kb Entries: 0
Articles: 0
Question SOLVED: Function needed for business days

Hi there...can anyone tell me the Access equivalent for Excel's NETWORKDAYS function? I'm trying to use DATEDIF, but I don't see an option to include a list of holidays.

Thanks!

Local Time: 11:53 PM
Local Date: 05-23-2013
Location:

 
Top
Old 07-23-2004, 06:01 AM   #2
SJ McAbney
 
SJ McAbney's Avatar

 
Joined: May 2004
Posts: 243
Kb Entries: 0
Articles: 0
Are you in the UK or elsewhere? If you are in the UK I can give you something that will calculate all working days and remove public holidays from the equation.

If not, I can give you the basic workdays formula. I also have some US holiday formulae.

Another method is to set a reference to Excel and make use of the NETWORKDAYS formula.

Local Time: 05:53 AM
Local Date: 05-24-2013
Location:

 
Top
Old 07-23-2004, 06:04 AM   #3
TonyJollans
 
TonyJollans's Avatar

 
Joined: May 2004
Posts: 2,290
Kb Entries: 3
Articles: 0
I'm afraid there is no equivalent in Access. You need to create your own table of holidays and write your own function. I'll knock something up and post back - if no one else does so first.


Enjoy,
Tony

---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.

I'm (slowly) building my own site: www.WordArticles.com

Local Time: 05:53 AM
Local Date: 05-24-2013
Location:

 
Top
Old 07-23-2004, 06:04 AM   #4
babsc01
 
babsc01's Avatar

 
Joined: Jun 2004
Posts: 53
Kb Entries: 0
Articles: 0
Nope, I am in the US. Thanks!

Local Time: 11:53 PM
Local Date: 05-23-2013
Location:

 
Top
Old 07-23-2004, 06:05 AM   #5
babsc01
 
babsc01's Avatar

 
Joined: Jun 2004
Posts: 53
Kb Entries: 0
Articles: 0
Tony...I've seen the following from another board, but I can't quite see how to post the holidays:

VBA:
Function NetWorkDays(Start_Date As Date, End_Date As Date, Holidays() As = Variant) As Integer Dim intX As Integer Dim intCount As Integer Dim intUbound As Integer Dim tempEnd_Date As Date intX =3D DateDiff("d", Start_Date, End_Date) intCount =3D 0 Do Until intCount =3D intX Select Case WeekDay(DateAdd("d", intCount, Start_Date)) Case vbSaturday, vbSunday intX =3D intX - 1 End Select intCount =3D intCount + 1 Loop tempEnd_Date =3D DateAdd("d", intCount, Start_Date) For intX =3D LBound(Holidays) To UBound(Holidays) If Holidays(intX) >=3D Start_Date And Holidays(intX) <=3D = tempEnd_Date Then intCount =3D intCount - 1 End If Next NetWorkDays =3D intCount End Function
VBA tags courtesy of www.thecodenet.com

Local Time: 11:53 PM
Local Date: 05-23-2013
Location:

 
Top
Old 07-23-2004, 06:16 AM   #6
SJ McAbney
 
SJ McAbney's Avatar

 
Joined: May 2004
Posts: 243
Kb Entries: 0
Articles: 0
Quote:
 
Originally Posted by: Abulafia
Another method is to set a reference to Excel and make use of the NETWORKDAYS formula.

Scrub that; I forgot that NETWORKDAYS isn't a standard function and is part of the Analysis Toolpak.

Have a look at Pat Hartman's database on this forum.

This extra post by myself here may also be of some interest to you.

Local Time: 05:53 AM
Local Date: 05-24-2013
Location:

 
Top
Old 07-23-2004, 06:50 AM   #7
babsc01
 
babsc01's Avatar

 
Joined: Jun 2004
Posts: 53
Kb Entries: 0
Articles: 0
Abulafia...the function you pointed me to works great. I think this thread can be considered SOLVED. But, the user will have to create a new table called tblHolidays (below) within the same DB as the code for it to work. Easy enough to do. THANKS!!!!

1/1/20015/28/20017/4/20019/3/200111/22/200111/23/200112/25/20011/1/20025/27/20027/4/20029/2/200211/28/200211/29/200212/25/2002
1/1/20035/26/20037/4/20039/1/200311/27/200311/28/200312/25/20031/1/20045/31/20047/5/20049/6/200411/25/200411/26/200412/24/200412/31/2004

Last edited by TonyJollans : 07-23-2004 at 07:02 AM. Reason: Break long string

Local Time: 11:53 PM
Local Date: 05-23-2013
Location:

 
Top
Old 07-23-2004, 06:50 AM   #8
babsc01
 
babsc01's Avatar

 
Joined: Jun 2004
Posts: 53
Kb Entries: 0
Articles: 0
YUK...sorry for the terrible post!

Local Time: 11:53 PM
Local Date: 05-23-2013
Location:

 
Top
Old 07-23-2004, 06:53 AM   #9
TonyJollans
 
TonyJollans's Avatar

 
Joined: May 2004
Posts: 2,290
Kb Entries: 3
Articles: 0
babsc01 - that routine takes in an array of holidays, something like ..

VBA:
Dim Holidays(2) As Date Holidays(0) = #01 Jan 2004# Holidays(1) = #25 Dec 2004# Holidays(2) = #26 Dec 2004#
VBA tags courtesy of www.thecodenet.com

Then call like ..

VBA:
NetWorkDays(StartDate, EndDate, Holidays)
VBA tags courtesy of www.thecodenet.com

.. or without declaring your own array, you can just do ..

VBA:
NetWorkDays(StartDate, EndDate, Array(#01 Jan 2004#, #25 Dec 2004#, #26 Dec 2004#))
VBA tags courtesy of www.thecodenet.com


Seems little point in me knocking anything up now


Enjoy,
Tony

---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.

I'm (slowly) building my own site: www.WordArticles.com

Local Time: 05:53 AM
Local Date: 05-24-2013
Location:

 
Top
Old 07-23-2004, 07:03 AM   #10
TonyJollans
 
TonyJollans's Avatar

 
Joined: May 2004
Posts: 2,290
Kb Entries: 3
Articles: 0
I edited your post - just broke the long string in two


Enjoy,
Tony

---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.

I'm (slowly) building my own site: www.WordArticles.com

Local Time: 05:53 AM
Local Date: 05-24-2013
Location:

 
Top
Closed Thread



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 09:53 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express