I made a form to update historical data and a subform that is used to check the result! Everything works fine except one small problem.
The result of my date comparison is not correct for any date that is the first date of any month in 2018!!! (it is driving me craziee)
So my code is below:
Private Sub runbtn_Click()
Me.Refresh
Dim theminimum As String
Dim theprodscID As String
Dim thepurchasedate As Date
If IsNull(Me.purchasedate) = False Then
theprodscID = Str(Me.prodscID)
thepurchasedate = Me.purchasedate.Value
'minimum textbox
theminimum = "Select Top 1 [update value]" & _
" From [product and shareclass level data update]" & _
" Where [product and shareclass level data update].[dataID] =" & Str(1) & _
" And [product and shareclass level data update].[prodscID] =" & theprodscID & _
" And ([product and shareclass level data update].[timestamp] <= #" & thepurchasedate & "#)" & _
" Order by [product and shareclass level data update].[timestamp] DESC"
If CurrentDb.OpenRecordset(theminimum).RecordCount = 0 Then
Me.minimum = Null
Else
Me.minimum = CurrentDb.OpenRecordset(theminimum).Fields(0).Value
End If
So for example, if I have records update value: "hello" on 01/05/2018; "bye" on 01/08/2017. Then, when I enter the purchase date as 01/05/2018, it should give me "hello" but not "bye"! However, if I enter 12/05/2018, it gives me "hello", which is correct! I find that this error occurs for some dates that I put as timestamp, but works for other dates!
I checked my code and I think it is correct. I don't know what the problem is!
Thanks, Phylly