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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highest Value in Record 3

Status
Not open for further replies.

james2308

MIS
May 15, 2001
17
GB
I have a table with 3 date fields. At least one of them is always filled in, sometimes all of them. In a query, I need to return the single highest value of these fields for each record.

Does anyone have any idea how I can do this? It is starting to hurt my brain.

Many thanks,

James
 


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 (IsMissing(varMyVals(Idx))) Then
            GoTo NextVal
        End If
        If (varMyVals(Idx) > MyMax) Then
            MyMax = varMyVals(Idx)
        End If
NextVal:
    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
 
Michael,

I can see what this does, tahnk you. However (and I am showing my shallow knowledge here), how do I apply this to my query?

Thanks for all the help, i really appreciate it.

James.
 
Michael,

Pure genius.....

Worth a star by any standards....

Craig
 
MyMax: basMaxVal(Field1, Field2, ...Fieldn)

Craig, et al. Thanks. Kudos (Stars ... ) and JOB OFFERS Welcomed.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thanx, this half solves my problem... I'm trying to return the earliest of 4 time fields - with the added complications of midnight and some if not all of the fields may be blank.
Any ideas would be gratefully received. B4 my boss gives me a good slapping LOL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top