There was no need to substitute the names: parameters in functions are just
"place holders" for the values that you pass to them. Also, it's not clear
whether you just forgot to include the End Function in what you pasted: you
definitely need that line as well.
Create a new module, and store that function in the new module. Do not name
the module WorkDayDiff: modules cannot have the same name as functions or
subs.
Now, create a query that includes your DateFrom and DateTo fields. Add a
computed field to that query by typing the following into an empty cell on
the "Field" line in the query builder:
TotalDays: WorkDayDiff([DateFrom], [DateTo])
If there's a chance that DateFrom or DateTo might be null, you'll need to
make some changes. What do you want to do in that case: perhaps use today's
date instead of the Null? If so, change the computed field from above to:
TotalDays: WorkDayDiff(Nz([DateFrom], Date()), Nz([DateTo], Date()))
Otherwise, you'll have to change the function declaration from
Function WorkDayDiff( _
DateFrom As Date , _
DateTo As Date _
) As Long
to
Function WorkDayDiff( _
DateFrom As Variant , _
DateTo As Variant _
) As Long
and add checking in the function to correctly handle Null values. The
revised function below will return 0 if either of the dates are Null:
Function WorkDayDiff( _
DateFrom As Variant , _
DateTo As Variant _
) As Long
If IsNull(DateFrom) Or IsNull(DateTo) Then
WorkDayDiff = 0
Else
WorkDayDiff = DateDiff("d", DateFrom, DateTo) - _
DateDiff("ww", DateFrom, DateTo, 1) * 2 - _
IIf(Weekday(DateTo, 1) = 7, _
IIf(Weekday(DateFrom, 1) = 7, 0, 1), _
IIf(Weekday(DateFrom, 1) = 7, -1, 0))
End If
End Function