legalhustler
Well-known Member
- Joined
- Jun 5, 2014
- Messages
- 1,158
- Office Version
-
- 365
- Platform
-
- Windows
I'm not sure if this post should be in the Access or Excel forum (Moderatrator you can remove one or the other) but here is the issue that I need help with:
In Excel, I went to Other Data Sources and selected From Microsoft Query and selected my Access query to import into Excel but I get the following error message: "Undefined function 'Workdays' in expression"
FYI - I have a Weekdays function and Workdays function <acronym title="visual basic for applications">VBA</acronym> codes in two separate modules (both are set as Public function) in my Access database. I'm not sure what the problem is when I am trying to import the query into Excel. Here is the <acronym title="visual basic for applications">VBA</acronym> code for the Workdays function:
In Excel, I went to Other Data Sources and selected From Microsoft Query and selected my Access query to import into Excel but I get the following error message: "Undefined function 'Workdays' in expression"
FYI - I have a Weekdays function and Workdays function <acronym title="visual basic for applications">VBA</acronym> codes in two separate modules (both are set as Public function) in my Access database. I'm not sure what the problem is when I am trying to import the query into Excel. Here is the <acronym title="visual basic for applications">VBA</acronym> code for the Workdays function:
Code:
Option Compare Database
Option Explicit
Public Function Workdays(ByRef startDate As Date, _
ByRef endDate As Date, _
Optional ByRef strHolidays As String = "Holidays" _
) As Integer
' Returns the number of workdays between startDate
' and endDate inclusive. Workdays excludes weekends and
' holidays. Optionally, pass this function the name of a table
' or query as the third argument. If you don't the default
' is "Holidays".
On Error GoTo Workdays_Error
Dim nWeekdays As Integer
Dim nHolidays As Integer
Dim strWhere As String
' DateValue returns the date part only.
startDate = DateValue(startDate)
endDate = DateValue(endDate)
nWeekdays = Weekdays(startDate, endDate)
If nWeekdays = -1 Then
Workdays = -1
GoTo Workdays_Exit
End If
strWhere = "[Holiday] >= #" & startDate _
& "# AND [Holiday] <= #" & endDate & "#"
' Count the number of holidays.
nHolidays = DCount(Expr:="[Holiday]", _
Domain:=strHolidays, _
Criteria:=strWhere)
Workdays = nWeekdays - nHolidays
Workdays_Exit:
Exit Function
Workdays_Error:
Workdays = -1
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Workdays"
Resume Workdays_Exit
End Function
Last edited: