andy_dyer
Registered User.
- Local time
- Today, 14:21
- Joined
- Jul 2, 2003
- Messages
- 806
Hi everyone...
I've got the following code that I've found on this forum to calculate my working days between two selected dates:
What I also need to take into account is the start and finish dates for individual staff members...
So - I need to check the working days between two input dates for a member of staff unless the member of staff started after the calculation start date ([forms![frmquery]![txtStart]) or finished before the calculation finish date ([forms![frmquery]![txtFinish])
In have a staff table (tblStaff) with StaffID, User Name, Department Name, User Start Date, User End Date...
Is there a way I can get my code to check the start and end dates and subsititue in instead of the input dates for these members of staff when making the calculation?
I'll then need a way of rolling this up so I get a individual total and then a department total... but one step at a time...
I hope I've explained that properly - many thanks for anyone's help??
I've got the following code that I've found on this forum to calculate my working days between two selected dates:
Code:
Function CalcWkDays2(dteStartDate As Date, dteEndDate As Date, _
YCnt As Boolean, Optional pExcl As String = "17") As Integer
'*****************************************************
'Name: CalcWkDays2 (Function)
'Purpose: Count # of days between two dates, with
' options to:
' (1) Include or exclude the start date in count
' (2) Specify weekdays to exclude (default
' set to Saturday (7) & Sunday (1). To exclude
' Tuesday (3) & Thursday (5), specify "35".
'Parameters: dteStartDate & dteEndDate formatted as dates
' YCnt: Specify True to include start date in
' count, False to exclude it.
' pExcl: Weekdays to exclude
'Inputs: From debug window:
' (1) ? CalcWkDays2(#01/01/01#, #07/01/01#, True)
' (2) ? CalcWkDays2(#01/01/01#, #07/01/01#, False)
' (3) ? CalcWkDays2(#01/01/01#, #07/01/01#, True, "")
' (4) ? CalcWkDays2(#01/01/01#, #07/01/01#, False,"")
' (5) ? CalcWkDays2(#07/01/01#, #01/01/01#, False,"")
' (6) ? CalcWkDays2(#01/01/01#, #07/01/01#, False,"23456")
'Output: (1) 130; (2) 129; (3) 182; (4) 181; (5) -181; (6) 52
'
'*****************************************************
Dim n As Integer, wdays As String, datehold As Date, dteFlag As Boolean
dteFlag = False
'Reverse the dates if they were input backwards
If dteStartDate > dteEndDate Then
datehold = dteStartDate
dteStartDate = dteEndDate
dteEndDate = datehold
dteFlag = True
End If
n = 0
dteStartDate = dteStartDate - Not (YCnt)
'days to exclude (7 & 1 unless other specified)
wdays = pExcl
Do While dteStartDate <= dteEndDate
n = n + IIf(InStr(wdays, Weekday(dteStartDate)) = 0, 1, 0)
dteStartDate = dteStartDate + 1
Loop
'return negative value if the Start Date
'was initially greater than the End Date
CalcWkDays2 = n * IIf(dteFlag, -1, 1)
End Function
What I also need to take into account is the start and finish dates for individual staff members...
So - I need to check the working days between two input dates for a member of staff unless the member of staff started after the calculation start date ([forms![frmquery]![txtStart]) or finished before the calculation finish date ([forms![frmquery]![txtFinish])
In have a staff table (tblStaff) with StaffID, User Name, Department Name, User Start Date, User End Date...
Is there a way I can get my code to check the start and end dates and subsititue in instead of the input dates for these members of staff when making the calculation?
I'll then need a way of rolling this up so I get a individual total and then a department total... but one step at a time...
I hope I've explained that properly - many thanks for anyone's help??