I am passing dates to a function (below) and sending the output to a text
field. I am getting an error 'Input String Was Not in Correct Format with
Dates' when I run the report.
I have tried the following expressions for the text field, with the same
results:
=Code.determineTimePeriod("01/01/1900", "01/01/1900")
=Code.determineTimePeriod(cdate("01/01/1900") ,cdate("01/01/1900") )
Eventually I want to pass in SQL datetime attributes from a dataset, but I
wanted to get it working with straight up strings first.
Function determineTimePeriod(ByVal currentDate As Date, ByVal rowDate As
Date) As String
Dim currentYear As Integer
Dim currentMonth As Integer
Dim currentDay As Integer
Dim startOfCurrentPeriod As Date
Dim monthOffset As Long
currentYear = DatePart(DateInterval.Year, currentDate)
currentMonth = DatePart(DateInterval.Month, currentDate)
currentDay = DatePart(DateInterval.Day, currentDate)
startOfCurrentPeriod = DateValue(currentMonth + "/" + "01" +
currentYear)
If (rowDate <> Nothing) Then
monthOffset = DateDiff(DateInterval.Month, startOfCurrentPeriod,
rowDate)
If (monthOffset <= -1) Then
Return "Prior"
ElseIf (monthOffset > 0 And monthOffset < 1) Then
Return "Current"
ElseIf (monthOffset > 1 And monthOffset < 2) Then
Return "Next"
ElseIf (monthOffset > 2) Then
Return "Future"
End If
Else
Return "TBR"
End If