Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max Of Record

Status
Not open for further replies.

Shaft128

Technical User
Nov 27, 2001
8
GB
Here is a simplified version of what I am trying to do. I have a table similar to the one below, with each record having 4 fields, A, B, C, D.

[A] [C] [D]
1 1 2 4 8
2 7 9 6 2
3 3 5 10 2
4 13 5 7 6


I want to be able to find the highest value for each record, and display it in a new field called [MAX], so that my table will look like this.

[A] [C] [D] [MAX]
1 1 2 4 8 8
2 7 9 6 2 9
3 3 5 10 2 10
4 13 5 7 6 13


I can do this task using EXCEL, by using the MAX function and highlighting each row, and I can do this task so that it gives the MAX for each field and I can also do this task so that it gives the MAX value for the whole table but I cannot do this task for each record. Can anyone help?


 
Try the following with the field list as the argument list, as in:

Max: basMaxVal([A], , [C], [D])

Code:
Public Function basMaxVal(ParamArray varMyVals() As Variant) As Variant

    'Michael Red 10/25/2001
    'To return the MAXIMUM or a series of values

    Dim Idx As Integer
    Dim MyMax As Variant

    For Idx = 0 To UBound(varMyVals())
        If (varMyVals(Idx) > MyMax) Then
            MyMax = varMyVals(Idx)
        End If
    Next Idx

    basMaxVal = MyMax

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top