Yes, you can call a function from a query, but create the function in a module.
You can also send a parameter with the function and filter the date for each
mechine
Function GetDateDiff(MechineNum as long)
Dim MyDB As Database, MyRec As Recordset, MyLargDate As Variant
Set MyDB = CodeDb
Set MyRec = MyDB.OpenRecordset("SELECT MyTable.MyDateField FROM MyTable
Where [MechineNumField] = " & MechineNum & " ORDER BY MyTable.MyDateField
DESC")
If not MyRec.eof then
MyLargDate = MyRec!MyDateField
MyRec.MoveNext
GetDateDiff = DateDiff("d", MyRec!MyDateField, MyLargDate)
End if
End Function
But be carefull, if the mechine apear few time in the query, then you will
run the function to many time, and for no reason.
Scott J. said:
Thanks for the help! One other question though. Can you call a function
from a query? I would call the function in one query (that has the machine
and date information), then the function would run a query for that machine
up to that date and perform the date difference. The date difference would
be a field in the initial query.
Basically I want to call the function for each record in a query. Can that
be done?
Thanks again!