Help with Averages

C

Chuck216

Hi

I have 14 unbound text boxes on a report that calculate a percentage based
on 2 set of bound text boxes these unbound boxes do not always have something
in them (only if wait time is >=15).


If Me.Wait12_1 >= 15 Then
Me.Text194 = [Hour12-1] / [THC]
Else
Me.Text194 = ""
End If


It’s the same code for each of the 14 unbound boxes just the numbers are
changed. This is done in the Format Detail event of the report.

My question is I would like to have another text box that would give me an
average of these 14, I don’t want empty boxes included in the average.

Any help with this is greatly appreciated

Chuck
 
D

Douglas J. Steele

You'll need code like:

Dim lngNonEmpty As Long
Dim sngAverage As Single
Dim sngSum As Single

lngNonEmpty = 0
sngSum = 0

If Me.Text194 <> "" Then
lngNonEmpty = lngNonEmpty + 1
sngSum = sngSum + Me.Text194
End If

If Me.Text195 <> "" Then
lngNonEmpty = lngNonEmpty + 1
sngSum = sngSum + Me.Text195
End If

If Me.Text196 <> "" Then
lngNonEmpty = lngNonEmpty + 1
sngSum = sngSum + Me.Text196
End If

....
If lngNonEmpty > 0 then
sngAverage = sngSum / lngNonEmpty
End If
 
C

Chuck216

That works Great

Thanks!!!




Douglas J. Steele said:
You'll need code like:

Dim lngNonEmpty As Long
Dim sngAverage As Single
Dim sngSum As Single

lngNonEmpty = 0
sngSum = 0

If Me.Text194 <> "" Then
lngNonEmpty = lngNonEmpty + 1
sngSum = sngSum + Me.Text194
End If

If Me.Text195 <> "" Then
lngNonEmpty = lngNonEmpty + 1
sngSum = sngSum + Me.Text195
End If

If Me.Text196 <> "" Then
lngNonEmpty = lngNonEmpty + 1
sngSum = sngSum + Me.Text196
End If

....
If lngNonEmpty > 0 then
sngAverage = sngSum / lngNonEmpty
End If

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Chuck216 said:
Hi

I have 14 unbound text boxes on a report that calculate a percentage based
on 2 set of bound text boxes these unbound boxes do not always have
something
in them (only if wait time is >=15).


If Me.Wait12_1 >= 15 Then
Me.Text194 = [Hour12-1] / [THC]
Else
Me.Text194 = ""
End If


It's the same code for each of the 14 unbound boxes just the numbers are
changed. This is done in the Format Detail event of the report.

My question is I would like to have another text box that would give me an
average of these 14, I don't want empty boxes included in the average.

Any help with this is greatly appreciated

Chuck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top