S
Samantha
I have used one of the methods (via a function) posted on this forum to
calculate a date that is 2 days prior to the start date. I called out this
function "PrevWorkingDay" from a query. The date calculation appears to be
ok.
The problem that I am having is setting a date parameter base on this
PrevDate on the query. The PrevDate does not seem to be a acting like a date
should be. When the date parameter is >=12/25/2007, there is no result.
When the date parameter is >=#12/25/2007#, the result is only for dates
Here is the problematic query:
SELECT dbo_WOHeader.WONumber, dbo_WOHeader.ClosedFlag,
dbo_WOHeader.StartDate, dbo_WOHeader.RequiredDate,
IIf(IsNull([dbo_WOHeader].[StartDate]),"",Format(PrevWorkingDay([dbo_WOHeader].[StartDate],5,2),"mm/dd/yyyy")) AS PrevDate
FROM dbo_WOHeader
WHERE (((dbo_WOHeader.ClosedFlag)=0) AND
((IIf(IsNull([dbo_WOHeader].[StartDate]),"",Format(PrevWorkingDay([dbo_WOHeader].[StartDate],5,2),"mm/dd/yyyy")))>=12/25/2007));
Here is function "PrevWorkingDay" :
Public Function PrevWorkingDay(FromThisDate As Date, WorkingDays As Integer,
MinusDays As Integer) As Date
Dim ThisWeekDay As String
On Error GoTo PrevWorkingDay_Error
PrevWorkingDay = FromThisDate 'Default all ok
If WorkingDays < 5 Or WorkingDays > 7 Then
'Out of Range
GoTo PrevWorkingDay_Exit
End If
ThisWeekDay = Format(DateAdd("d", -MinusDays, FromThisDate), "ddd")
If WorkingDays = 5 Then 'start with 5 days per week
If Format(FromThisDate, "ddd") = "Mon" Then
If ThisWeekDay = "Sat" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1 + 1), FromThisDate)
ElseIf ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 2 + 1), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays + 1), FromThisDate)
End If
Else 'Not a Friday
If ThisWeekDay = "Sat" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1), FromThisDate)
ElseIf ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 2), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays), FromThisDate)
End If
End If
ElseIf WorkingDays = 6 Then '6 days per week
If Format(FromThisDate, "ddd") = "Mon" Then
If ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1 + 1), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays), FromThisDate)
End If
Else 'Not a Friday
If ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays), FromThisDate)
End If
End If
End If
PrevWorkingDay_Exit:
Exit Function
PrevWorkingDay_Error:
MsgBox Err.Number & Err.Description, , "PrevWorkingDay"
Resume PrevWorkingDay_Exit
End Function
calculate a date that is 2 days prior to the start date. I called out this
function "PrevWorkingDay" from a query. The date calculation appears to be
ok.
The problem that I am having is setting a date parameter base on this
PrevDate on the query. The PrevDate does not seem to be a acting like a date
should be. When the date parameter is >=12/25/2007, there is no result.
When the date parameter is >=#12/25/2007#, the result is only for dates
Any help is very much appreciated, as I've spent days on this already!=12/25/2007 but excludes 2008 (there are supposed to have 2008 data).
Here is the problematic query:
SELECT dbo_WOHeader.WONumber, dbo_WOHeader.ClosedFlag,
dbo_WOHeader.StartDate, dbo_WOHeader.RequiredDate,
IIf(IsNull([dbo_WOHeader].[StartDate]),"",Format(PrevWorkingDay([dbo_WOHeader].[StartDate],5,2),"mm/dd/yyyy")) AS PrevDate
FROM dbo_WOHeader
WHERE (((dbo_WOHeader.ClosedFlag)=0) AND
((IIf(IsNull([dbo_WOHeader].[StartDate]),"",Format(PrevWorkingDay([dbo_WOHeader].[StartDate],5,2),"mm/dd/yyyy")))>=12/25/2007));
Here is function "PrevWorkingDay" :
Public Function PrevWorkingDay(FromThisDate As Date, WorkingDays As Integer,
MinusDays As Integer) As Date
Dim ThisWeekDay As String
On Error GoTo PrevWorkingDay_Error
PrevWorkingDay = FromThisDate 'Default all ok
If WorkingDays < 5 Or WorkingDays > 7 Then
'Out of Range
GoTo PrevWorkingDay_Exit
End If
ThisWeekDay = Format(DateAdd("d", -MinusDays, FromThisDate), "ddd")
If WorkingDays = 5 Then 'start with 5 days per week
If Format(FromThisDate, "ddd") = "Mon" Then
If ThisWeekDay = "Sat" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1 + 1), FromThisDate)
ElseIf ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 2 + 1), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays + 1), FromThisDate)
End If
Else 'Not a Friday
If ThisWeekDay = "Sat" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1), FromThisDate)
ElseIf ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 2), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays), FromThisDate)
End If
End If
ElseIf WorkingDays = 6 Then '6 days per week
If Format(FromThisDate, "ddd") = "Mon" Then
If ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1 + 1), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays), FromThisDate)
End If
Else 'Not a Friday
If ThisWeekDay = "Sun" Then
PrevWorkingDay = DateAdd("d", -(MinusDays + 1), FromThisDate)
Else
PrevWorkingDay = DateAdd("d", -(MinusDays), FromThisDate)
End If
End If
End If
PrevWorkingDay_Exit:
Exit Function
PrevWorkingDay_Error:
MsgBox Err.Number & Err.Description, , "PrevWorkingDay"
Resume PrevWorkingDay_Exit
End Function