G
genoki
I have been struggling with this for a few days. Racked my brains.
Coming up with dead ends. Searched through the web & groups. It is
both the 'puzzle solving' and VBA looping logic I am having problems
with. Can anyone give me some pointers?
I need to calculate the time it takes to complete an application,
accounting for:
- workday 6 am - 6 pm (clock stops during non-work hours)
- holidays listed in a separate table with begin & end date/times
(clock stops on holidays)
- 'events' which are in separate table related to each application and
have start and end date/times (clock stops until 'event' is complete)
I need to determine if the time to complete the application was within
a service agreement 'max time to complete'.
I have three tables:
1. Application - has Application Start and Completed date/time fields
and each application has unique Application_ID
2. Events - each event has unique Events_ID and foreign key relating
to each Application_ID
3. Holidays - days that are regular holidays and specific company
holidays with Holidays_Date, Holidays_BeginHours, Holidays_EndHours
I need to determine the following:
1. Total time to complete excluding holidays and working hours, and
event durations.
2. Expected date/time of completion based on current date/time
excluding holidays and working hours, and event durations.
************************************************
Example data:
Application Start: July 1, 2008 13:00 (clock starts)
Event 1 Start: July 1, 2008 14:00 (clock stops)
Event 1 End: July 2, 2008 11:00 (clock starts)
Event 2 Start: July 2, 2008 16:00 (clock stops)
Event 2 End: July 4, 2008 19:00 (Note: Event ends out of regular
working hours so clock would start at next working day eg July 4 06:00
but July 4 was a holiday so clock starts July 5 06:00 instead)
Application Completed: July 6, 2008 13:00 (clock stops)
*******************************************************
My conjectured VBA so far:
' Declare variables
' Create a DAO recordset for Events grouped by Application to loop
through
' Does Application have any Events?
If recordset has no events for application then
' Does Application have an Application_Completion date?
If no Application_Completion date then
' Calculate duration using current date (ie still open)
SLA_Duration = DateDiff("d" Application_Start, Now ())
Else
' Calculate duration using completion date
SLA_Duration = DateDiff("d" Application_Start,
Application_Completion )
End if
Else ' Application has Events
' Loop through events calculating
i = i + 1
1 -- Application_Start to Event 0 Start ---> DateDiff("d"
Application_Start, Event 0 start)
2 -- Event 0 to Event n+1, etc ---> DateDiff("d" Event_Start,
Event_End)
3 -- Event n+1 End to Application_Completion ---> DateDiff("d" Event n
+1 End, Application_Completion)
SLA_Duration = Sum(1 + 2 + 3)
Next i
End loop
End If
Where do I put in the logic that tests whether any of the dates is
outside of workday hours or a holiday? Then how do I have the logic
'jump ahead' to the next work day start to use that date/time instead
to start the clock and perform calculations?
Any pointers at all greatly appreciated!
Genoki
Coming up with dead ends. Searched through the web & groups. It is
both the 'puzzle solving' and VBA looping logic I am having problems
with. Can anyone give me some pointers?
I need to calculate the time it takes to complete an application,
accounting for:
- workday 6 am - 6 pm (clock stops during non-work hours)
- holidays listed in a separate table with begin & end date/times
(clock stops on holidays)
- 'events' which are in separate table related to each application and
have start and end date/times (clock stops until 'event' is complete)
I need to determine if the time to complete the application was within
a service agreement 'max time to complete'.
I have three tables:
1. Application - has Application Start and Completed date/time fields
and each application has unique Application_ID
2. Events - each event has unique Events_ID and foreign key relating
to each Application_ID
3. Holidays - days that are regular holidays and specific company
holidays with Holidays_Date, Holidays_BeginHours, Holidays_EndHours
I need to determine the following:
1. Total time to complete excluding holidays and working hours, and
event durations.
2. Expected date/time of completion based on current date/time
excluding holidays and working hours, and event durations.
************************************************
Example data:
Application Start: July 1, 2008 13:00 (clock starts)
Event 1 Start: July 1, 2008 14:00 (clock stops)
Event 1 End: July 2, 2008 11:00 (clock starts)
Event 2 Start: July 2, 2008 16:00 (clock stops)
Event 2 End: July 4, 2008 19:00 (Note: Event ends out of regular
working hours so clock would start at next working day eg July 4 06:00
but July 4 was a holiday so clock starts July 5 06:00 instead)
Application Completed: July 6, 2008 13:00 (clock stops)
*******************************************************
My conjectured VBA so far:
' Declare variables
' Create a DAO recordset for Events grouped by Application to loop
through
' Does Application have any Events?
If recordset has no events for application then
' Does Application have an Application_Completion date?
If no Application_Completion date then
' Calculate duration using current date (ie still open)
SLA_Duration = DateDiff("d" Application_Start, Now ())
Else
' Calculate duration using completion date
SLA_Duration = DateDiff("d" Application_Start,
Application_Completion )
End if
Else ' Application has Events
' Loop through events calculating
i = i + 1
1 -- Application_Start to Event 0 Start ---> DateDiff("d"
Application_Start, Event 0 start)
2 -- Event 0 to Event n+1, etc ---> DateDiff("d" Event_Start,
Event_End)
3 -- Event n+1 End to Application_Completion ---> DateDiff("d" Event n
+1 End, Application_Completion)
SLA_Duration = Sum(1 + 2 + 3)
Next i
End loop
End If
Where do I put in the logic that tests whether any of the dates is
outside of workday hours or a holiday? Then how do I have the logic
'jump ahead' to the next work day start to use that date/time instead
to start the clock and perform calculations?
Any pointers at all greatly appreciated!
Genoki