In MSaccess is is very easy to incorporate a complex function in the access module in a query.
Eg If I have a mdb table that has a list of start times in seconds since midnight and I want to display the actual time as well in another temporary column.
Select * From MyTable StartTime, ConvertSecondsToTime(StartTime) as ShowTime
The function the above statement uses is a bit too complicated to put in the Sql statement and the one that works in MSAccess is as follows:-
I have tried various combinations in a vb6 recordset criteria statement but keep getting syntax errors.
My question how do I do this - if this is possible?
Do I perhaps have to perhaps incorporate a few IIFs in the query instead or can I reference the function directly?
Eg If I have a mdb table that has a list of start times in seconds since midnight and I want to display the actual time as well in another temporary column.
Select * From MyTable StartTime, ConvertSecondsToTime(StartTime) as ShowTime
The function the above statement uses is a bit too complicated to put in the Sql statement and the one that works in MSAccess is as follows:-
Code:
Function ConvertSecondsToTime(Seconds As Long) As String
'Converts the number of seconds since midnight to normal time formats for sign
Dim Hours As Double, Minutes As Single, Temp As Long
Temp = Seconds
If Temp = 0 Then ConvertSecondsToTime = "": Exit Function
If Temp > 86400 Then Temp = Temp - 86400 'after midnight
Hours = Temp / (3600)
Minutes = (Hours - Int(Hours)) * 60
'insert a leading space when hours is a single digit
ConvertSecondsToTime = Right("00" & Int(Hours), 2) & ":" & Right("00" & Int(Minutes), 2)
End Function
I have tried various combinations in a vb6 recordset criteria statement but keep getting syntax errors.
My question how do I do this - if this is possible?
Do I perhaps have to perhaps incorporate a few IIFs in the query instead or can I reference the function directly?