Function to Calculate "true" checkboxes on continuous subform! (1 Viewer)

rpdecker

New member
Local time
Yesterday, 17:46
Joined
Oct 23, 2012
Messages
1
I have found the following function and I've been able to get it working, but on my continuous form it only counts 1 even if more boxes are checked. I can not use =Abs(Sum([the field])) in the record source of a field, as the field that I need to show the calculated number is linked to a table. I am fully aware of the arguments for not recording calculated information, but this is to record the Total number of students present based on the number of "Present" checkboxes that are checked in the Continuous Subform. How can I alter this function code to get the sum of checked boxes in my continuous form.

Here is the code!

Function CountChecked() As Integer
Dim intTotalChecked As Integer
Dim ctl As Control
intTotalChecked = 0
For Each ctl In Me
If ctl.ControlType = acCheckBox Then
If ctl.Value = True Then
intTotalChecked = intTotalChecked + 1
End If
End If
Next
CountChecked = intTotalChecked
End Function

Any help would be great!
 

boblarson

Smeghead
Local time
Yesterday, 17:46
Joined
Jan 12, 2001
Messages
32,059

I can not use =Abs(Sum([the field])) in the record source of a field, as the field that I need to show the calculated number is linked to a table.


Then you are doing it wrong. You should NOT be storing this in your table. You are violating the rules of normalization and also your integrity of your data. You DISPLAY it - you don't store it. If you need it elsewhere you use a QUERY to DISPLAY it - you don't store it.
 

Users who are viewing this thread

Top Bottom