Ilovexfiles
Registered User.
- Local time
- Today, 15:09
- Joined
- Jun 27, 2017
- Messages
- 37
Hi all
I have this function below, and I have it as an expression in a query, and I get the error: 'Undefined function 'AddWeekDays' in expression.'
I am new to this, am I missing something?
Expression:
AddWeekDays([AdmitDate],3)
The goal of this expression is to take the "AdmitDate" field and add 3 Weekdays to it, creating a "Due Date"
Function (derived from online):
On Error GoTo PROC_ERR
Dim intCounter As Integer
Dim intDirection As Integer
Dim datNewDate As Date
Dim lngWeeks As Long
Dim intDaysLeft As Integer
datNewDate = datDateIn
If intDays > 0 Then
intDirection = 1
Else
intDirection = -1
End If
lngWeeks = Fix(Abs(intDays) / 5)
If lngWeeks > 0 Then
datNewDate = datNewDate + lngWeeks * 7 * intDirection
End If
intDaysLeft = Abs(intDays) - lngWeeks * 5
For intCounter = 1 To intDaysLeft
datNewDate = datNewDate + 1 * intDirection
If intDirection > 0 Then
' Increment date
If Weekday(datNewDate) = 7 Then
datNewDate = datNewDate + 2
End If
Else
' Decrement date
If Weekday(datNewDate) = 1 Then
datNewDate = datNewDate - 2
End If
End If
Next intCounter
AddWeekDays = datNewDate
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.AddWeekdays"
Resume PROC_EXIT
End Function
I have this function below, and I have it as an expression in a query, and I get the error: 'Undefined function 'AddWeekDays' in expression.'
I am new to this, am I missing something?
Expression:
AddWeekDays([AdmitDate],3)
The goal of this expression is to take the "AdmitDate" field and add 3 Weekdays to it, creating a "Due Date"
Function (derived from online):
On Error GoTo PROC_ERR
Dim intCounter As Integer
Dim intDirection As Integer
Dim datNewDate As Date
Dim lngWeeks As Long
Dim intDaysLeft As Integer
datNewDate = datDateIn
If intDays > 0 Then
intDirection = 1
Else
intDirection = -1
End If
lngWeeks = Fix(Abs(intDays) / 5)
If lngWeeks > 0 Then
datNewDate = datNewDate + lngWeeks * 7 * intDirection
End If
intDaysLeft = Abs(intDays) - lngWeeks * 5
For intCounter = 1 To intDaysLeft
datNewDate = datNewDate + 1 * intDirection
If intDirection > 0 Then
' Increment date
If Weekday(datNewDate) = 7 Then
datNewDate = datNewDate + 2
End If
Else
' Decrement date
If Weekday(datNewDate) = 1 Then
datNewDate = datNewDate - 2
End If
End If
Next intCounter
AddWeekDays = datNewDate
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.AddWeekdays"
Resume PROC_EXIT
End Function