Function ConYear(PDate As Date, ParamArray varMyVals() As Variant) As String
'*******************************************
'Name: ConYear (Function)
'Purpose: Returns the user-defined FY date range
' based on date input (PDate)
'In response to: [url]http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=13051[/url]
'Inputs: ? conyear(#4/4/02#, #7/1/98#, #6/30/99#, #7/1/99#, #3/31/00#, #4/1/00#, #3/31/01#, #4/1/01#, #3/31/02#,#4/1/02#,#9/30/02)
'Output: See debug window
'Note: 1998-1999 7/1/98 - 6/30/99
' 1999-2000 7/1/99 - 3/31/00
' 2000-2001 4/1/00 - 3/31/01
' 2001-2002 4/1/01 - 3/31/02
' 2002-2003 4/1/02 - 9/30/03
'*******************************************
Dim idx As Long, i As Integer
i = UBound(varMyVals)
'is input date < lower limit or > upper limit?
If PDate < varMyVals(0) Or PDate > varMyVals(i) Then
ConYear = "Date out of bounds"
GoTo Exit_ConYear
Else
'cycle thru until input date <= upper limit of a date range
For idx = 1 To UBound(varMyVals()) Step 2
If PDate <= varMyVals(idx) Then
ConYear = Year(varMyVals(idx - 1)) & "-" & Year(varMyVals(idx))
GoTo Exit_ConYear
End If
Next idx
End If
Exit_ConYear:
Exit Function
End Function