I was using the DateDiff function in one of my queries (as below). This would work for me in situations where there was no SWDATERESOLVED yet. It would just leave the CRT blank.
CRT: DateDiff("d",SWB_SW_CASE!SWDATECREATED,[SWDATERESOLVED])
But, because I need to EXCLUDE weekends, I needed to use code rather than the DateDiff function.
So here is my expression in the query:
CRT: GetWorkDays(SWB_SW_CASE!SWDATECREATED,[SWDATERESOLVED])
and this is the code:
However, if there is no EndDate, the query bombs on me.
I get a
Microsoft Visual Basic pop-up Error:
Run-time error ‘94’:
Invalid use of Null
If I click on Debug, it takes me to this line of the code:
So I assume it is not knowing what to do when there is no EndDate. Not sure what the difference is in having my DateDiff in the Module vs directly in the query... but it is. How do I rectify this so that I can get a blank CRT when the SWDATERESOLVED is blank?
Thanks
Katie
CRT: DateDiff("d",SWB_SW_CASE!SWDATECREATED,[SWDATERESOLVED])
But, because I need to EXCLUDE weekends, I needed to use code rather than the DateDiff function.
So here is my expression in the query:
CRT: GetWorkDays(SWB_SW_CASE!SWDATECREATED,[SWDATERESOLVED])
and this is the code:
Code:
Option Compare Database
Option Explicit
Public Function GetWorkDays(sStartDate, sEndDate) As Long
Dim iDays As Long
Dim iWorkDays As Long
Dim sDay
Dim i As Long
iDays = DateDiff("d", sStartDate, sEndDate)
iWorkDays = 0
For i = 0 To iDays
'First day of the week is sunday
sDay = Weekday(DateAdd("d", i, sStartDate))
If sDay <> 1 And sDay <> 7 Then
iWorkDays = iWorkDays + 1
End If
Next
GetWorkDays = iWorkDays
End Function
However, if there is no EndDate, the query bombs on me.
I get a
Microsoft Visual Basic pop-up Error:
Run-time error ‘94’:
Invalid use of Null
If I click on Debug, it takes me to this line of the code:
Code:
iDays = DateDiff("d", sStartDate, sEndDate)
So I assume it is not knowing what to do when there is no EndDate. Not sure what the difference is in having my DateDiff in the Module vs directly in the query... but it is. How do I rectify this so that I can get a blank CRT when the SWDATERESOLVED is blank?
Thanks
Katie