Help with my function vba code

C

Cam

Hello,

I created a module function code to calculate # of days between 3 dates
excluding weekend and holiday. When I put it in query, CalcDays:
calcWorkdays([StartDate],[EndDate]), it gave me a undefined function
'CalcWorkdays' in expression error. Not sure what is wrong with my code.

Function calcWorkDays(dtmStart As Date, dtmEnd As Date) As Integer
On Error GoTo CalcWorkDays_Error
calcWorkDays = DateDiff("d", dtmStart, dtmEnd) - _
(DateDiff("ww", dtmStart, dtmEnd, 7) + _
DateDiff("ww", dtmStart, dtmEnd, 1)) + 1
calcWorkDays = calcWorkDays - DCount("*", "qryHolidays",
"[CalDate]between #" _
& dtmStart & "# And #" & dtmEnd & "#")

CalcWorkDays_Exit:
On Error Resume Next
Exit Function

CalcWorkDays_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure CalcWorkDays of Module modDateFunctions"
GoTo CalcWorkDays_Exit

End Function
 
D

Douglas J. Steele

You didn't happen to name the module calWorkDays, did you? Modules cannot
have the same name as functions or subs.
 

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

Similar Threads

can someone explain this 1
CalcWorkDays error 1
Can't query DateDiff 3
Number of days 9
Infamous Business Day Count 7
Calcworkdays Revision? 2
Calculate Buisness Days Open 2
working days 4

Top