M
MikeT
Hi,
I am using Access 2007, however and would like to calculate the number of
days between two dates.
I have the following function that i have saved to a module:
Function CalcWorkdays(StartDate, EndDate) As Integer
Dim LTotalDays As Integer
Dim LSaturdays As Integer
Dim LSundays As Integer
On Error GoTo Err_Execute
CalcWorkdays = 0
If IsDate(StartDate) And IsDate(EndDate) Then
If EndDate <= StartDate Then
CalcWorkdays = 0
Else
LTotalDays = DateDiff("d", StartDate - 1, EndDate)
LSaturdays = DateDiff("ww", StartDate - 1, EndDate, 7)
LSundays = DateDiff("ww", StartDate - 1, EndDate, 1)
'Workdays is the elapsed days excluding Saturdays and Sundays
CalcWorkdays = LTotalDays - LSaturdays - LSundays
End If
End If
Exit Function
Err_Execute:
'If error occurs, return 0
CalcWorkdays = 0
End Function
I am trying to pull the module through my query and am using the following
expression
Expr1: CalcWorkdays(#01/01/2009#,#31/12/2009#)
however when i run the query i get a dialog box with the following:
Undefined function 'CalcWorkdays' in expression
I'm not sure what i'm doing wrong? My table is set up as StartDate and
EndDate, which i originally included in the query but this did not work
either. I'm sure this is a simple oversight, but I can't seem to see it
myself?
I am using Access 2007, however and would like to calculate the number of
days between two dates.
I have the following function that i have saved to a module:
Function CalcWorkdays(StartDate, EndDate) As Integer
Dim LTotalDays As Integer
Dim LSaturdays As Integer
Dim LSundays As Integer
On Error GoTo Err_Execute
CalcWorkdays = 0
If IsDate(StartDate) And IsDate(EndDate) Then
If EndDate <= StartDate Then
CalcWorkdays = 0
Else
LTotalDays = DateDiff("d", StartDate - 1, EndDate)
LSaturdays = DateDiff("ww", StartDate - 1, EndDate, 7)
LSundays = DateDiff("ww", StartDate - 1, EndDate, 1)
'Workdays is the elapsed days excluding Saturdays and Sundays
CalcWorkdays = LTotalDays - LSaturdays - LSundays
End If
End If
Exit Function
Err_Execute:
'If error occurs, return 0
CalcWorkdays = 0
End Function
I am trying to pull the module through my query and am using the following
expression
Expr1: CalcWorkdays(#01/01/2009#,#31/12/2009#)
however when i run the query i get a dialog box with the following:
Undefined function 'CalcWorkdays' in expression
I'm not sure what i'm doing wrong? My table is set up as StartDate and
EndDate, which i originally included in the query but this did not work
either. I'm sure this is a simple oversight, but I can't seem to see it
myself?