Max Function Help

L

Lost and Confused

Is it possible to do a max expression with a constant in a query? I have
tried to no avail. What I need to do is have it display the max of [Acreage
Price] or [200]. [Acreage Price] itself is a function of [Total # Acres]*.25.
I tried doing a huge expression with the hopes of beginners luck, but that
didn't work. Can you please tell me how to do this expression in as plain of
language as possible? I've gotten dizzy from trying to read the other posts
on max functions.

For reference, the big picture I'm trying to break down looks like:
Total Premium= Max(acreage*.25, 200) + AI*26

It looks so simple, but it's created my own level of personal hell.

First off, the answer is "No, I have no idea what I'm doing." I'm taking
over the Access management from someone else and instead of learning by
creating, I'm learning by editing. My only previous experience is staying as
far away as possible.

Thanks in advance!
 
D

Dale Fye

Don't know what version of Access you are using, but the ones I have don't
have a MAX( ) function built in. They do have a DMAX( ) function, but that
is designed to retrieve the maximum value in a field of a query or table.

I've written a function (fnMaximum) that will return what you are looking
for. Copy this into a code module and call it instead of MAX( )

Public Function fnMaximum(ParamArray MyArray()) As Variant

Dim intLoop As Integer

fnMaximum = Null
For intLoop = LBound(MyArray) To UBound(MyArray)
If IsNull(MyArray(intLoop)) Then
'do nothing
ElseIf IsNull(fnMaximum) Then
fnMaximum = MyArray(intLoop)
ElseIf MyArray(intLoop) > fnMaximum Then
fnMaximum = MyArray(intLoop)
End If
Next intLoop

End Function

This function can be used to compare any number of parameters (well, I'm
sure there is a limit to how many parameter can be passed in an array, but I
don't know what it is). Additionally, it can be used to compare any
datatypes, I use it alot with dates.

HTH
Dale
 

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