If it's not too much trouble, could you post a screenshot or some instructions on how to add a Date Field to a form? All I can find is "Text Box".A date or time should be saved in a date field.
If not try
[Value] <= format(date(),"dd/mm/yyyy")
Not directly, I'm using data from a Date Field inside the table but not the actual field. The value for the particular Date I'm using inside the form is set by vba code.Is the control bound to a table? If the control is bound the bound field should be a date field not a text field.
Can you show the code? Are you setting a string value or date value in code?
I.e
Txtbox = "10/9/2023"
Or
Txtbox = #9/10/2023#
Me.IforceDate_Text.Value = CalculateDeleteDate(eanValue)
Debug.Print "Function Result: " & CalculateDeleteDate(eanValue)
Debug Result below:
inside the function deletionDate: 03/11/2023
Function Result: 03/11/2023
Me.IforceDate_Text.Value = Format(CalculateDeleteDate(eanValue), "dd/mm/yyyy")
Debug.Print "Function Result: " & Format(CalculateDeleteDate(eanValue), "dd/mm/yyyy")
Function CalculateDeleteDate(eanValue As String) As Date
Dim lastAdjustmentDate As Date
Dim deleteAfterDays As Integer
deleteAfterDays = DLookup("DeleteAfterDays", "tbl_settings", "ID = 1")
lastAdjustmentDate = DLookup("DT", "tbl_crt_stock", "EAN = '" & eanValue & "'")
' Calculate the date when the stock will be deleted
Dim deletionDate As Date
deletionDate = DateAdd("d", deleteAfterDays, lastAdjustmentDate)
Debug.Print "inside the function deletionDate: " & deletionDate
CalculateDeleteDate = deletionDate
End Function
Dates are a constant issue, for example, if I want to save a date in a table and I want it to have the format dd/mm/yyyy, I have to insert it as mm/dd/yyyy or it will be the other way around. No idea what is going on.Not sure why this is happening since you appear to be returning an actual date with your function and not a string formatted as a date. But there it definitely looks like string comparison happening even though you are returning dates.
if today is
06/10/2023
the string
"06/10/2023" is less than the strings
"06/11/2023"
"07/9/2023"
and greater than the string
"03/09/2023"
which is what you show
Print now(), cdec(Now()) , Date(), cdec(Date())
05/10/2023 09:13:57 45204.3846875 05/10/2023 45204