Need for Minimum function

  • Thread starter Thread starter Guy
  • Start date Start date
G

Guy

I have to find the minimum of different values, but no
aggregate!

e.g. : Minimum of ( Table1.Cost1 , Table2.Cost1 , Table3,
Cost1 )

Thank you very much for helping me out.
 
The best solution would be to change the data structure to a normalized one,
where you don't have to search across multiple fields or tables.

However, this function will return the lowest numeric value from a list
passed in. For example, if you have Table1, Table2, and Table3 in a query,
you could enter a calcualted field into the query grid (Field row) like
this:
MinCost: Minimum(Table1.Cost1, Table2.Cost1, Table3.Cost1 )

Function Minimum(ParamArray varValues()) As Variant
Dim i As Integer 'Loop controller.
Dim varMax As Variant 'Lowest value found so far.

varMax = Null 'Initialize to null

For i = LBound(varValues) To UBound(varValues)
If IsNumeric(varValues(i)) Then
If varMax <= varValues(i) Then
'do nothing
Else
varMax = varValues(i)
End If
End If
Next

Minimum = varMax

End Function
 
Back
Top