A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Min function



 
 
Thread Tools Display Modes
  #1  
Old September 4th, 2008, 03:37 PM posted to microsoft.public.access.queries
Boon
external usenet poster
 
Posts: 115
Default Min function

Hi there,

I want to use a function that finds a minimum between a list of number in
query.

I don't know what this function is, so I will call it "Func"

For example, in one column in query design view I would like to write
something like this:

Minimum: Func(4,5,6,2,9)

Then when I run the query, I would like to see "2" in column "Minimum"

Thanks a lot
Boon


  #2  
Old September 4th, 2008, 03:56 PM posted to microsoft.public.access.queries
Dale Fye
external usenet poster
 
Posts: 2,651
Default Min function

There is no Access function to do this. But I have one I've created and used
in the past. Copy this code and put it in a code module. Then you can call
it from your query or in code.

Public Function fnMin(ParamArray SomeValues() As Variant) As Variant

'Accepts an array of parameters, preferably of the same data type,
'but can be any type including NULL values
'fnMin(3, 7, 10) = 3
'fnMin(#9/1/07#, #9/15/07#, #10/1/06#) = #9/1/07#

Dim intLoop As Integer
Dim myMin As Variant

For intLoop = LBound(SomeValues) To UBound(SomeValues)

If IsNull(SomeValues(intLoop)) Then
'do nothing
ElseIf IsEmpty(myMin) Or (SomeValues(intLoop) myMin) Then
myMin = SomeValues(intLoop)
End If

Next

fnMin = myMin

End Function
--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



"Boon" wrote:

Hi there,

I want to use a function that finds a minimum between a list of number in
query.

I don't know what this function is, so I will call it "Func"

For example, in one column in query design view I would like to write
something like this:

Minimum: Func(4,5,6,2,9)

Then when I run the query, I would like to see "2" in column "Minimum"

Thanks a lot
Boon



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:07 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.