Wrox Programmer Forums
|
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 March 15th, 2006, 10:59 AM
Authorized User
 
Join Date: Jan 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default NetworkDays in Access?

Is there a way for Access to recognize holidays in a function? I found the DateDiffW function that counts just weekdays, but I also need it to count holidays as well, within the same function. Here is the coding that I have so far, and it's working well. What I'm using it for is a "on hold" "off hold" calculation, that will be pulled into measurables. Any help would be appreciated!

Code:
Public Function DateDiffW(BegDate, EndDate)
    Const SUNDAY = 1
    Const SATURDAY = 7
    Dim NumWeeks As Integer

    If BegDate > EndDate Then
        DateDiffW = 0
    Else
        Select Case Weekday(BegDate)
            Case SUNDAY: BegDate = BegDate + 1
            Case SATURDAY: BegDate = BegDate + 2
        End Select
        Select Case Weekday(EndDate)
            Case SUNDAY: EndDate = EndDate - 2
            Case SATURDAY: EndDate = EndDate - 1
        End Select
        NumWeeks = DateDiff("ww", BegDate, EndDate)
        DateDiffW = NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate)
    End If

End Function

 
Old March 15th, 2006, 02:01 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to add a table of holidays. From there you can do a select query on the table with dates within the range you're looking at, convert the query into a recordset, and subtract the size of the recordset from the number of days you returned with the DateDiffW function.

 
Old March 15th, 2006, 02:13 PM
Authorized User
 
Join Date: Jan 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the information. I will try it.

I'm still new to programming. on the
Code:
NumWeeks = DateDiff("ww", BegDate, EndDate)
is there a way to tell it not to give an error on a "null" value? I'm running a query, and using the DateDiffW in an expression, to give me a total of dates, minus "onhold", "offhold" dates, but there are times that there are no values in the "onhold", "offhold" fields, and when I run it, it is giving me an error on this line.


 
Old March 15th, 2006, 04:28 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

IIf(IsNull(value),0,value)
or
IIf(IsNull(value),'0',value)
or
IIf(IsNull(value),'',value)

One of those three should work depending on the data type required.. I think.

 
Old March 16th, 2006, 10:30 AM
Authorized User
 
Join Date: Jan 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sorry to be a pain about this, but I guess I'm not getting this.

Here is the expression line that I have in my query:

Expr2: IIf(IsNull([OnHoldREQ]),DateDiffW([Requisition Rec'd],[Submitted to Manager]),DateDiffW([Requisition rec'd],[Submitted to Manager])-DateDiffW([OnHoldREQ],[OffHoldREQ]))

When I run this, I get an error in my coding, highlighting this line:
Code:
NumWeeks = DateDiff("ww", BegDate, EndDate)
I can understand a little what you're explaining, but I'm getting lost when I'm trying to write it into my code.

I started under the NumWeeks code line with:

Code:
IIf(IsNull(BegDate),' ',
but then I get stuck, telling it what to do from that point. Any help would be great!! :D








Similar Threads
Thread Thread Starter Forum Replies Last Post
401.3 Access denied due to Access Control List cforsyth .NET Framework 2.0 8 May 28th, 2009 01:56 PM
SQL Access/ASP.NET data access issue saeta57 SQL Server ASP 1 July 4th, 2004 04:29 PM
SQL Access/ASP.NET data access issue saeta57 Classic ASP Databases 1 July 4th, 2004 03:32 PM
ADE file in Access 2000 <---> Access XP ginoitalo Access 3 April 14th, 2004 09:06 PM
Access XP VBA compatibility issues w/ Access 2000 bourgeois02 Access VBA 1 August 19th, 2003 04:14 PM





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