Undefined function ‘DateDiffW’ in expression

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
 
K

Ken Snell [MVP]

The module must have a different name than any functions, subroutines, etc.
that are in your database project. Change the name of the module.
 
R

Raj

Ken,
Thank you!!

Ken Snell said:
The module must have a different name than any functions, subroutines, etc.
that are in your database project. Change the name of the module.

--

Ken Snell
<MS ACCESS MVP>

Raj said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top