Max of 3 values

timothyl

Registered User.
Local time
Today, 08:22
Joined
Jun 4, 2009
Messages
92
Hello, I am making a parts order form and I need to get the max value from three fields

MSRP MarkUp HcpcPricing

On MS web site they have a verbose solution, Would love to have a more succinct one if anyone has it . Thanks
 
Thanks for replying will check it out
 
Written by MajP, Works perfectly

There are probably a lot of versions. In access there are a lot of instance of a blank field (null value). This handles those cases.

CODE

Public Function getMax(ParamArray vals() As Variant) As Variant
Dim myVal As Variant
Dim maxVal As Variant

For Each myVal In vals
If Not IsNull(myVal) Then
maxVal = myVal
Exit For
End If
Next myVal

If IsNull(maxVal) Then Exit Function

For Each myVal In vals
If Not IsNull(myVal) Then
If myVal > maxVal Then
maxVal = myVal
End If
End If
Next myVal
getMax = maxVal
End Function

2nd Way By KHP, works perfectly

'A generic function to get the max value of an arbirtrary numbers of same type values:
Public Function myMax(ParamArray Args())
Dim i As Long, rv
For i = 0 To UBound(Args)
If IsNull(rv) Or rv < Args(i) Then rv = Args(i)
Next
myMax = rv
End Function
 
Last edited:

Users who are viewing this thread

Back
Top Bottom