Undefined Function in Expression

Xcalibur

Registered User.
Local time
Today, 15:33
Joined
Oct 3, 2004
Messages
22
I created a function and when I try to use it in my query I am getting the error message Undefined Function in Expression.

This is the function:

Option Compare Database
Option Explicit

Function Next_Weekday(DateField As Date) As Date

If Next_Weekday((DateField)) = 1 Then
Next_Weekday = (DateField) + 1
Else
If Next_Weekday((DateField)) = 7 Then
Next_Weekday = (DateField) + 2
Else
Next_Weekday
End If

End Function

Any suggestions as to why it won't recognize it?

Thanks.
 
The problem is you are trying to call the function that you are trying to declare :eek:. The code just doesn't make sense. I'm surprised your computer didn't go into an infinite loop then meltdown through the earth's core.

What exactly are you trying to do with this function?

Chris
 
You're making it more difficult than necessary. Give this a try:
Code:
NextWorkDay = [dteMyDate] + IIf(WeekDay([dteMyDate]) > 5, 9 - WeekDay([dteMyDate]), 1)

Added:
Re your original question.
(1) In referring to argument DateField, you've used the name of the function, i.e.
If Next_Weekday((DateField)) = 1 -- replace it with
If Weekday(DateField) = 1 -- etc
(2) Your Else statement: Next_Weekday should read
Next_Weekday = DateField + 1
(3) Your logic is flawed in that it doesn't consider the possibility that Weekday(DateField) = 6, i.e. Friday

HTH - Bob
 
Last edited:

Users who are viewing this thread

Back
Top Bottom