I have written a function that runs through a recordset and find the lowest value from ceratin fields in a row.
I want to use this as a column in a new query but do not know how to incorperate it into the sql query definition.
My function is :
Function LowestPrice()
Dim db As Database
Dim qry As QueryDef
Dim rs As DAO.Recordset
Dim i As Integer
Dim MyArray(100) As Variant
Dim currentVal As Variant
Set db = CurrentDb()
Set qry = db.QueryDefs("MyQuery"
Set rs = qry.OpenRecordset
Do While Not rs.EOF
currentVal = 0
For i = 0 To rs.Fields.Count - 1
If rs.Fields(i).name Like "*Price1" Then
MyArray(i) = rs.Fields(i).Value
End If
If MyArray(i) < currentVal Then
currentVal = MyArray(i)
End If
Next
LowestMultiPrice = currentVal
rs.MoveNext
Loop
End Function
I would like to then use results of the function to be a column in an SQL statement.
I want to use this as a column in a new query but do not know how to incorperate it into the sql query definition.
My function is :
Function LowestPrice()
Dim db As Database
Dim qry As QueryDef
Dim rs As DAO.Recordset
Dim i As Integer
Dim MyArray(100) As Variant
Dim currentVal As Variant
Set db = CurrentDb()
Set qry = db.QueryDefs("MyQuery"
Set rs = qry.OpenRecordset
Do While Not rs.EOF
currentVal = 0
For i = 0 To rs.Fields.Count - 1
If rs.Fields(i).name Like "*Price1" Then
MyArray(i) = rs.Fields(i).Value
End If
If MyArray(i) < currentVal Then
currentVal = MyArray(i)
End If
Next
LowestMultiPrice = currentVal
rs.MoveNext
Loop
End Function
I would like to then use results of the function to be a column in an SQL statement.