? basMaxField("tblGrade", "StuName", "Brett Duvall", 12, 13, 11, 0, 14, 15, 13, 16)
Asgn10
[code]
This block of code is the actual routine:
[code]
Public Function basMaxField(MyTbl As String, KeyFld As String, _
KeyVal As Variant, _
ParamArray MyAry() As Variant) As String
'Michael Red 5/7/2002 To Return the Fieldname of
'the MAX value of a set of values from a group of fields
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(MyTbl, dbOpenDynaset)
Dim Idx As Integer
Dim Jdx As Integer
Dim MaxVal As Variant
Dim MaxField As String
MaxVal = -1 * e ^ 38
rst.FindFirst (KeyFld = KeyVal)
Do While Idx <= UBound(MyAry) ' To rstTableName.Fields.Count - 1
If (MyAry(Idx) > MaxVal) Then
MaxVal = MyAry(Idx)
Do While Jdx <= rst.Fields.Count - 1
If (rst.Fields(Jdx).Value = MaxVal) Then
MaxField = rst.Fields(Jdx).name
Exit Do
End If
Jdx = Jdx + 1
Loop
End If
Idx = Idx + 1
Loop
basMaxField = MaxField
End Function