As I want started off as properly but it is probably something I have missed.
I have the following code, but if the date is before the 12th day of the month it swaps to US format dtmMax, so doesnt work.
Public Function fncGetMaxStatus(intRequest As Integer) As Integer
Dim dtmMax As Date
strSQL = "SELECT Max(RequestStatusDate) AS MaxDate " & _
"FROM tbl_RequestStatus " & _
"WHERE Request= " & intRequest & ";"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
If IsNull(rst!maxdate) Then
fncGetMaxStatus = 0
Else
dtmMax = rst!maxdate
'MsgBox dtmMax
strSQL = "SELECT Status " & _
"FROM tbl_RequestStatus " & _
"WHERE Request= " & intRequest & _
" AND format(RequestStatusDate, 'dd/mm/yyyy hh:nn:ss') = #" & Format(dtmMax, "dd/mm/yyyy hh:nn:ss"
& "#;"
Set rst = dbs.OpenRecordset(strSQL)
'MsgBox strSQL
If rst.EOF Then
fncGetMaxStatus = 0
Else
fncGetMaxStatus = rst!Status
End If
End If
rst.Close
Set dbs = Nothing
End Function
I would have thought that defining the format for both the field and the passed parameter then it should work. The alternative is to produce a query, and pass then pass the parameters to that object, but I rather like minimizing the number of objects in a database.
All suggestions gratefully received
If at first you don't succeed, try for the answer.
I have the following code, but if the date is before the 12th day of the month it swaps to US format dtmMax, so doesnt work.
Public Function fncGetMaxStatus(intRequest As Integer) As Integer
Dim dtmMax As Date
strSQL = "SELECT Max(RequestStatusDate) AS MaxDate " & _
"FROM tbl_RequestStatus " & _
"WHERE Request= " & intRequest & ";"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
If IsNull(rst!maxdate) Then
fncGetMaxStatus = 0
Else
dtmMax = rst!maxdate
'MsgBox dtmMax
strSQL = "SELECT Status " & _
"FROM tbl_RequestStatus " & _
"WHERE Request= " & intRequest & _
" AND format(RequestStatusDate, 'dd/mm/yyyy hh:nn:ss') = #" & Format(dtmMax, "dd/mm/yyyy hh:nn:ss"
Set rst = dbs.OpenRecordset(strSQL)
'MsgBox strSQL
If rst.EOF Then
fncGetMaxStatus = 0
Else
fncGetMaxStatus = rst!Status
End If
End If
rst.Close
Set dbs = Nothing
End Function
I would have thought that defining the format for both the field and the passed parameter then it should work. The alternative is to produce a query, and pass then pass the parameters to that object, but I rather like minimizing the number of objects in a database.
All suggestions gratefully received
If at first you don't succeed, try for the answer.