Option Compare Database
Option Explicit
Private m_date As Date
Private m_start
Private m_end
[COLOR="Green"]'********************************************************************
'* Sep 12 2012
'* Properties>
'*
'********************************************************************[/COLOR]
Property Get FiscalYear() As Long
FiscalYear = Year(Me.DateEnd)
End Property
Property Get DateStart() As Date
If IsEmpty(m_start) Then Calculate
DateStart = m_start
End Property
Property Get DateEnd() As Date
If IsEmpty(m_end) Then Calculate
DateEnd = m_end
End Property
[COLOR="Green"]'********************************************************************
'* Sep 12 2012
'* Methods>
'*
'********************************************************************[/COLOR]
Private Sub Class_Initialize()
m_date = Date
End Sub
Function LoadByYear(Year As Long) As cFiscalYear
Refresh
Set LoadByYear = Me.LoadByDate(DateSerial(Year, 1, 1))
End Function
Function LoadByDate(d1 As Date) As cFiscalYear
Refresh
m_date = DateValue(d1) [COLOR="Green"] 'make sure there is no time component[/COLOR]
Set LoadByDate = Me
End Function
Sub Refresh()
m_start = Empty
m_end = Empty
End Sub
Function GetWhereClauseExpression(DateFieldName As String) As String
GetWhereClauseExpression = _
"( " & _
DateFieldName & " >= #" & Me.DateStart & "# AND " & _
DateFieldName & " <= #" & Me.DateEnd & "# " & _
") "
End Function
Function ToString() As String
ToString = _
"Fiscal Year: " & Me.FiscalYear & vbCrLf & _
"Date Start.: " & Me.DateStart & vbCrLf & _
"Date End...: " & Me.DateEnd & vbCrLf & _
"WHERE......: " & Me.GetWhereClauseExpression("MyDate")
End Function
[COLOR="Green"]'********************************************************************
'* Sep 12 2012
'* Utils>
'*
'********************************************************************[/COLOR]
Private Sub Calculate()
If m_date = 0 Then Err.Raise 5, "cFiscalYear.Calculate()"
If Month(m_date) > 3 Then
m_start = DateSerial(Year(m_date), 4, 1)
m_end = DateSerial(Year(m_date) + 1, 3, 31)
Else
m_start = DateSerial(Year(m_date) - 1, 4, 1)
m_end = DateSerial(Year(m_date), 3, 31)
End If
End Sub