Hello All,
I'm using the follow block of code to create a three year date range for a particular quarter.
Code:
Public Function quarterDateRange(quarter As Integer) As String
Dim startDate As Date
Dim endDate As Date
If (quarter = 1) Then
startDate = CDate("1/1/" & Year(Date))
endDate = CDate("3/31/" & Year(Date))
ElseIf (quarter = 2) Then
startDate = CDate("4/1/" & Year(Date))
endDate = CDate("6/31/" & Year(Date))
ElseIf (quarter = 3) Then
startDate = CDate("7/1/" & Year(Date))
endDate = CDate("9/31/" & Year(Date))
ElseIf (quarter = 4) Then
startDate = CDate("10/1/" & Year(Date))
endDate = CDate("12/31/" & Year(Date))
End If
quarterDateRange = "Between #" & startDate & "# And #" & endDate & "# Or " & _
"Between #" & DateAdd("yyyy", -1, startDate) & "# And #" & DateAdd("yyyy", -1, endDate) & "# Or " & _
"Between #" & DateAdd("yyyy", -2, startDate) & "# And #" & DateAdd("yyyy", -2, endDate) & "#"
End Function
Then for example, if I run it in VBA as a test, such as
Code:
quarterDateRange(1)
i'll get the following:
Code:
Between #1/1/2017# And #3/31/2017# Or Between #1/1/2016# And #3/31/2016# Or Between #1/1/2015# And #3/31/2015#
which is exactly what I would want. If this output is pasted into my query under the date criteria it works. HOWEVER, using the function with an integer parameter the query returns nothing.
Any idea why the equivalent information returns different results.
Thank you,
Weekend Coder