Good day everyone, I have a MS Access function that I was using on a machine using the mm/dd/yyyy format but now have moved to a machine using the dd/mm/yyyy format.
Public Function fncERates(sEID As Long, PeriodEnd As Date) As Double
Dim strERates As String
Dim strPeriodEnd As String
PeriodEnd = CDate(Nz(PeriodEnd, 0))
strPeriodEnd = "#" & Format(PeriodEnd, "dd/mm/yyyy") & "#"
Debug.Print strPeriodEnd
strERates = "SELECT TOP 1 [ERate] FROM EmpStatus WHERE [EffDate] <= " & strPeriodEnd & " And EID = " & sEID & "" _
& " ORDER BY [EffDate] DESC"
With CurrentDb.OpenRecordset(strERates)
If Not (.BOF And .EOF) Then
fncERates = .Fields(0)
End If
End With
End Function
What it does is it returns the current Employee's pay rate based on the ending period. On debugging, fncERates(36,#12/13/21#) returns the correct rate ($25.00) but fncERates(36,#13/12/21#) returns 0 and Access sees #13/12/21# as 21/12/2013.
What can I do to fix the code to be universally read by different computers no matter the system's date format?
I am using Ms Access 2007 and Ms Access 2016.