Where to stick line this code?

jeromez

Registered User.
Local time
Today, 09:33
Joined
Nov 23, 2009
Messages
16
The following code calcuates the difference in work days between two
dates:

Code:
Function BusinessDays(PosHireDate, RepDate) As Long 
BusinessDays = (DateDiff("d", PosHireDate, RepDate) - _ 
(DateDiff("ww", PosHireDate, RepDate) * 2) + 1) + _ 
(Weekday(PosHireDate) = vbSunday) + _ 
(Weekday(RepDate) = vbSaturday) 
End Function

Date 1 = [PosHireDate] or Position Hire Date
Date 2 = [RepDate] or Report Date


when I execute my query I get "#ERROR" for those records where the
[PosHireDate} is 'blank" or null


if i use:
You can trap for a null: If isnull([PosHireDate]) then
BusinessDays = 1000

or you can use NZ: NZ([PosHireDate],Date()) is my favorite in that
it runs but produces an obvious error.

to correct the error message and allow me to execute the code

my question is
Where would this line of code go in my original code?

thanks
 
Hi;

Try

Function BusinessDays(PosHireDate, RepDate) As Long
BusinessDays = Nz(DateDiff("d", PosHireDate, RepDate), Date - (DateDiff _
("ww", PosHireDate, RepDate) * 2) + 1) + Nz(Weekday(PosHireDate), Date = vbSunday) + (Weekday _
(RepDate) = vbSaturday)
End Function
 

Users who are viewing this thread

Back
Top Bottom