fat controller
Slightly round the bend..
- Local time
- Today, 21:10
- Joined
- Apr 14, 2011
- Messages
- 758
I have been trying (unsuccessfully) to get an unbound text box on a form to show the average of four other text boxes on that form. A bit of searching led me to the code below as a possible solution, but it isn't working (clearly I am being thick again) 
My thinking was to have this code on the 'After Update' event (or maybe On Change?) of each of the four text boxes which would then give a running average in the box that shows the average?
Where am I going wrong?

Code:
Dim nbrFieldsUsed As Integer
Dim nbrTotal As Double
nbrFieldsUsed = 0
nbrTotal = 0
If Not IsNull(Me!txtEWT_STD_1) Then
nbrFieldsUsed = nbrFieldsUsed + 1
nbrTotal = nbrTotal + Me!txtEWT_STD_1
End If
If Not IsNull(Me!txtEWT_STD_2) Then
nbrFieldsUsed = nbrFieldsUsed + 1
nbrTotal = nbrTotal + Me!txtEWT_STD_2
End If
If Not IsNull(Me!txtEWT_STD_3) Then
nbrFieldsUsed = nbrFieldsUsed + 1
nbrTotal = nbrTotal + Me!txtEWT_STD_3
End If
If Not IsNull(Me!txtEWT_STD_4) Then
nbrFieldsUsed = nbrFieldsUsed + 1
nbrTotal = nbrTotal + Me!txtEWT_STD_4
End If
If nbrFieldsUsed = 0 Then
Me!txtEWT_STD_AVE = 0
Else
Me!txtEWT_STD_AVE = nbrTotal / nbrFieldsUsed
End If
Where am I going wrong?