Maximum of three fields.

  • Thread starter Thread starter Veti
  • Start date Start date
V

Veti

I have to develop a query which does a maximum across three columns an
use it for a calculation.

in excel this can be easily done by using the max(1,2,3) but in acces
max is for a column and not multi columns
 
Veti,

You are going to need to write a function for that and put it in a code
module, and call it in your query.

Public Function MaxVal(Paramarray varArray() as variant) as Variant

Dim intLoop as integer
MaxVal = varArray(lbound(varArray))
For intLoop = LBOUND(varArray) to UBOUND(varArray)
if varArray(intLoop) > MaxVal THEN MaxVal = varArray(intLoop)
Next intLoop

End Function

Then to use it in a query, just type what you want the column name to be,
followed by a colon, followed by:

MaxVal(Col1, Col2, Col3)

The SQL will look something like:

SELECT Col1, Col2, Col3, MaxVal(Col1, Col2, Col3) as Max
FROM yourTable

HTH
Dale
 
Back
Top