Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to calculate ( add-up ) all the controls in a form

Status
Not open for further replies.

hoym

Technical User
Sep 14, 2002
15
HK
Please HELP !

I wish to add up all the Controls in a form to a text control , say [A1]....[A5]

its OK when [A1]....[A5] all has a value but it doesn't work if any one of them is Null.

How can i manage it even any one of [A1]....[A5] is empty ?

Martin
 
Hi hoy,

If you're using VBA, then just check that the field isn't empty:

if(fieldname <> &quot;&quot;) then 'add it to list'.

regards,

Darrylle &quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot;
 
Code:
Public Function basSumVal(ParamArray varMyVals() As Variant) As Variant

    'Michael Red 12/1/2002
    'To return the SUM or a series of values

    'Sample Usage:
    '? basSumVal(1, 2, 3, 4, 5, 6)
    ' 21

    '? basSumVal(0, 1, 2, 4, 8, 16, 32, 64)
    ' 127

    Dim Idx As Integer
    Dim MySum As Variant

    For Idx = 0 To UBound(varMyVals())
        If (Not IsNull(varMyVals(Idx))) Then
            MySum = MySum + varMyVals(Idx)
        End If
    Next Idx

    basSumVal = MySum

End Function


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top