Minimum Function

B

BobV

Group:

Is there a Minimum Function in Access VBA, like there is in Excel, to
determine the smaller of several variables? In Excel, the function is
expressed as =MIN(value1, value2, value3,...).

I know that there is a DMin function in Access VBA that will determine the
smallest value in a field, but this is not what I am trying to do. I am just
trying to write a VBA statement that will find the smaller of several
variables and then set another variable equal to the smallest, for example:

varBonus=Min(varCalc1, varCalc2, varCalc3)

Your help on how to do this will be greatly appreciated.

Thanks,
BobV
 
A

Allen Browne

There is not a built-in function for this, but here is an example that does
the opposite of what you asked for:

Function Largest(ParamArray varValues()) As Variant

Dim i As Integer 'Loop controller.

Dim varMax As Variant 'Largest value found so far.



varMax = Null 'Initialize to null



For i = LBound(varValues) To UBound(varValues)

If IsNumeric(varValues(i)) Then

If varMax >= varValues(i) Then

'do nothing

Else

varMax = varValues(i)

End If

End If

Next



Largest = varMax

End Function
 
A

Alex Dybenko

no, but you can write your own, here for 2 values and dates, but you can
easy modify it:

Public Function Min(ByVal d1 As Date, ByVal d2 As Date) As Date
Min = d1
If d2 < d1 Then Min = d2
End Function
 
B

BobV

Thank you Allen & Alex for your help. This is the help I was looking for. I
will write my own simple function like you both suggested.

BobV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top