R
Raj
I hope this is the correct group for this question…
I am trying to use this function that I got from Microsoft site (below)
When I try and use a query using the DateDiffW function I get “Undefined
function ‘DateDiffW’ in expression†error is there something I am doing
incorrect?
I copied the text to a module, named the module “DateDiffW. I then placed
Days Requested: datediffW([startdate], [enddate]) in my query and I get the
error.
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
I am trying to use this function that I got from Microsoft site (below)
When I try and use a query using the DateDiffW function I get “Undefined
function ‘DateDiffW’ in expression†error is there something I am doing
incorrect?
I copied the text to a module, named the module “DateDiffW. I then placed
Days Requested: datediffW([startdate], [enddate]) in my query and I get the
error.
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