My fields would be seperate like [tote1] [tote2] [tote3]
I was hoping i could write a formula in my query to give me the average.
If i use excel could i then import that number into my access report.
Thanks Jeff for taking the time to help me. I sure appreciate it.
ed
grumble grump...
I really feel bad about doing this because it's letting you continue to
maintain a BAD DESIGN which *should absolutely be changed*. But I'll hold
my
nose and post it anyway...
Overelaborate, but you can pass AvgLowN the number of values that you want
to
average followed by any desired number of arguments. For your case, use
AvgLowN(2, [Tote1], [Tote2], [Tote3])
and it will average the two lowest of the three values.
Copy and paste the code between the ============ lines into a new Module;
select Debug... Compile <my project>; save the module as basAverage, and
try
it in your query.
==================
Private Sub bubble(N As Integer, arr() As Integer)
'N is the number of integers in the array'
'0 to N-1'
Dim I As Integer, J As Integer, P, Temp As Integer
For I = N - 1 To 0 Step -1
P = 0
For J = 0 To I
If arr(J) > arr(J + 1) Then
Temp = arr(J)
arr(J) = arr(J + 1)
arr(J + 1) = Temp
Else
P = P + 1
End If
If P = I Then GoTo premend
Next J
Next I
'premend = premature ending = all integers are allready sorted'
premend:
End Sub
Public Function AvgLowN(N As Integer, ParamArray arr()) As Integer
Dim iSum As Integer
Dim iPos As Integer
Dim arrN() As Integer
iSum = 0
If UBound(arr) >= N - 1 Then
ReDim arrN(UBound(arr()))
For iPos = 0 To UBound(arr)
arrN(iPos) = arr(iPos)
Next iPos
Call bubble(UBound(arrN), arrN)
For iPos = 0 To N - 1
iSum = iSum + arrN(iPos)
Next iPos
AvgLowN = iSum \ N
Else
MsgBox "Too few values provided!", vbOKOnly
AvgLowN = 0
End If
End Function
==================