Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Calculate Buisness Days Open

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pierre - 21 May 2007 17:51 GMT
I am using the following code to calculate buisness days which is working
fine, but it requires input of both start and end dates.
I would like to modify the code to calculate with the input start date and
use the current date if the end date field is null until a date is entered to
the end date field.

Function CalcWorkDays(dtmStart As Date, dtmEnd As Date) As Integer
Dim intTotalDays As Integer ' Counter for number of days
Dim dtmToday As Date ' To increment the date to compare
'Compliments of Dave Hargis

intTotalDays = DateDiff("d", dtmStart, dtmEnd) +1 'Start with total days
'Add one to include First Day

dtmToday = dtmStart 'Initiate compare date
Do Until dtmToday > dtmEnd
If Weekday(dtmToday, vbMonday) > 5 Then 'It is Saturday or Sunday

intTotalDays = intTotalDays - 1 'Take one day away for Weekend day

ElseIf Not IsNull(DLookup("[Holdate]", "Holidays", _
"[Holdate] = #" & dtmToday & "#")) Then 'It is a holiday
intTotalDays = intTotalDays - 1 'Take one day away for the Holiday

End If
dtmToday = DateAdd("d", 1, dtmToday) 'Add a day for next Compare

Loop 'Until dtmToday > dtmEnd All days have been compared

CalcWorkDays = intTotalDays 'Return the value
End Function

Can the code be modified that way? If not is there a different code I can use?

Thank You.
Dale Fye - 21 May 2007 21:30 GMT
Change the data type of the second parameter to Variant (this will allow it
to be null).  Then, check to see if it is NULL and if so, convert it to
todays date  You could even make the second parameter optional so if you only
pass it one date, it will automatically use todays date as the dtmEnd.

HTH
Dale

Function CalcWorkDays(dtmStart As Date, _
                                   Optional dtmEnd As Variant = NULL) As
Integer

   Dim intTotalDays As Integer ' Counter for number of days
   Dim dtmToday As Date ' To increment the date to compare
   'Compliments of Dave Hargis

   'Added this line    
   if ISNULL(dtmEnd) then dtmEnd = Date()

   intTotalDays = DateDiff("d", dtmStart, dtmEnd) +1 'Start with total days
   'Add one to include First Day

> dtmToday = dtmStart 'Initiate compare date
> Do Until dtmToday > dtmEnd
[quoted text clipped - 13 lines]
> CalcWorkDays = intTotalDays 'Return the value
> End Function

Signature

Email address is not valid.
Please reply to newsgroup only.

> I am using the following code to calculate buisness days which is working
> fine, but it requires input of both start and end dates.
[quoted text clipped - 31 lines]
>
> Thank You.
Pierre - 22 May 2007 12:38 GMT
That modification is just what I needed, it is working well.

Thank you very much.

> Change the data type of the second parameter to Variant (this will allow it
> to be null).  Then, check to see if it is NULL and if so, convert it to
[quoted text clipped - 71 lines]
> >
> > Thank You.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.