Undefined function for a module called in a query (1 Viewer)

jom1918

Registered User.
Local time
Today, 21:28
Joined
Apr 26, 2011
Messages
30
I hope someone can help me.

This module is giving me the "undefined function" error message when I try to run my query. I don't know why, but I have checked that there are no references with "missing" and there are not. I also added the word "Public" to the function becasue that was advised by another forum user. I thought it worked perfectly the first time I ran this query, but now it is not working and I do not recall making any changes. Can someone tell me what I have done wrong. I have called the module basFunctions:

Option Compare Database
'**********************************************************
'Declarations section of the module
'**********************************************************
Option Explicit

'==========================================================
' The DateAddW() function provides a workday substitute
' for DateAdd("w", number, date). This function performs
' error checking and ignores fractional Interval values.
'==========================================================
Public Function DateAddW(ByVal TheDate, ByVal Interval)
Dim Weeks As Long, OddDays As Long, Temp As String
If VarType(TheDate) <> 7 Or VarType(Interval) < 2 Or _
VarType(Interval) > 5 Then
DateAddW = TheDate
ElseIf Interval = 0 Then
DateAddW = TheDate
ElseIf Interval > 0 Then
Interval = Int(Interval)
' Make sure TheDate is a workday (round down).
Temp = Format(TheDate, "ddd")
If Temp = "Sun" Then
TheDate = TheDate - 2
ElseIf Temp = "Sat" Then
TheDate = TheDate - 1
End If
' Calculate Weeks and OddDays.
Weeks = Int(Interval / 5)
OddDays = Interval - (Weeks * 5)
TheDate = TheDate + (Weeks * 7)
' Take OddDays weekend into account.
If (DatePart("w", TheDate) + OddDays) > 6 Then
TheDate = TheDate + OddDays + 2
Else
TheDate = TheDate + OddDays
End If
DateAddW = TheDate
Else ' Interval is < 0
Interval = Int(-Interval) ' Make positive & subtract later.
' Make sure TheDate is a workday (round up).
Temp = Format(TheDate, "ddd")
If Temp = "Sun" Then
TheDate = TheDate + 1
ElseIf Temp = "Sat" Then
TheDate = TheDate + 2
End If
' Calculate Weeks and OddDays.
Weeks = Int(Interval / 5)
OddDays = Interval - (Weeks * 5)
TheDate = TheDate - (Weeks * 7)
' Take OddDays weekend into account.
If (DatePart("w", TheDate) - OddDays) < 2 Then
TheDate = TheDate - OddDays - 2
Else
TheDate = TheDate - OddDays
End If
DateAddW = TheDate
End If
End Function
 

WayneRyan

AWF VIP
Local time
Today, 12:28
Joined
Nov 19, 2002
Messages
7,122
jom,

What jumps out at me ...

Public Function DateAddW(ByVal TheDate, ByVal Interval) As Date

Wayne
 

jom1918

Registered User.
Local time
Today, 21:28
Joined
Apr 26, 2011
Messages
30
Hi Warrne,

I added As Date and I still get the same message. Thanks for trying to help though. Must be something else.
 

jom1918

Registered User.
Local time
Today, 21:28
Joined
Apr 26, 2011
Messages
30
HI again Warren,

I figured out what I was doing wrong. The As Date was part of it. The other part was me having a blonde moment. I had a typo in the query and had mis-spelled the DATEADDW function. Doh! Thanks.
 

Users who are viewing this thread

Top Bottom