Max and Min of unbound text boxes

Scottyk537

Registered User.
Local time
Today, 11:59
Joined
May 25, 2006
Messages
48
I have a form with about 100 unbound text boxes. How do I get the Max and Min values of these boxes? I spilt these boxes into groups of 10 and I need to find the Max and Min values of each group of 10?
I was hoping not to have this calculation run in VB because there is alot of other code running in the background. If possible I would like this calculation to run on the form level.
I know one way of doing it, but it would require me to make about 100 more text boxes that arn't visible.
There has got to be an easy way of doing this!!!!

Scotty
 
I got it.................
I threw this code in a module, and I'm able to run this from the form level.
Hope this helps someone else out there!!!
Code:
Function Min(ParamArray avValues() As Variant) As Variant
    Dim vThisItem As Variant, vThisElement As Variant
    
    On Error Resume Next
    For Each vThisItem In avValues
        If IsArray(vThisItem) Then
            For Each vThisElement In vThisItem
                Min = Min(vThisElement, Min)
            Next
        Else
            If vThisItem < Min Then
                If Not IsEmpty(vThisItem) Then
                    Min = vThisItem
                End If
            ElseIf IsEmpty(Min) Then
                Min = vThisItem
            End If
        End If
    Next
    On Error GoTo 0
End Function

Code:
Function Max(ParamArray avValues() As Variant) As Variant
    Dim vThisItem As Variant, vThisElement As Variant
    
    On Error Resume Next
    For Each vThisItem In avValues
        If IsArray(vThisItem) Then
            For Each vThisElement In vThisItem
                Max = Max(vThisElement, Max)
            Next
        Else
            If vThisItem > Max Then
                If Not IsEmpty(vThisItem) Then
                    Max = vThisItem
                End If
            ElseIf IsEmpty(Max) Then
                Max = vThisItem
            End If
        End If
    Next
    On Error GoTo 0
End Function
So my control source in my text box looks like:
=Max(text1,text2,text3,text4,text5)
 
I'm sorry............this code works...........
Code:
Function RMin(ParamArray avValues() As Variant) As Variant
    Dim vThisItem As Variant, vThisElement As Variant
    
    On Error Resume Next
    For Each vThisItem In avValues
        If IsArray(vThisItem) Then
            For Each vThisElement In vThisItem
                RMin = RMin(vThisElement, RMin)
            Next
        Else
            If vThisItem < RMin Then
                If Not IsEmpty(vThisItem) Then
                    RMin = vThisItem
                End If
            ElseIf IsEmpty(RMin) Then
                RMin = vThisItem
            End If
        End If
    Next
    On Error GoTo 0
End Function
Code:
Function RMax(ParamArray avValues() As Variant) As Variant
    Dim vThisItem As Variant, vThisElement As Variant
    
    On Error Resume Next
    For Each vThisItem In avValues
        If IsArray(vThisItem) Then
            For Each vThisElement In vThisItem
                RMax = RMax(vThisElement, RMax)
            Next
        Else
            If vThisItem > RMax Then
                If Not IsEmpty(vThisItem) Then
                    RMax = vThisItem
                End If
            ElseIf IsEmpty(RMax) Then
                RMax = vThisItem
            End If
        End If
    Next
    On Error GoTo 0
End Function
In the control source you call it with:
=Val(Rmin([text1],[text2],[text3],[text4],[text5],[text6],[text7],[text8],[text9],[text10]))
 
please guidence

hi Scottyk537
thans for this code. can i let you send a sampel db with used this code.
i wante hide min max bottuon on my form dy code but i can not used code in db.
thank
 
What you need to do is change the Min Max settings of the form to None

minmax.jpg
 
hi Groundrush;
many thanks.
I do this, but i want hide buttons by code.
I get code for hide min max buttons of windows.
 

Users who are viewing this thread

Back
Top Bottom