By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 2,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

Calculate number of true checkboxes in Continuous Form

P: 2
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!

Expand|Select|Wrap|Line Numbers
  1. Function CountChecked() As Integer
  3. Dim intTotalChecked As Integer
  4. Dim ctl As Control
  6. intTotalChecked = 0
  7.  For Each ctl In Me
  8.     If ctl.ControlType = acCheckBox Then
  9.       If ctl.Value = True Then
  10.          intTotalChecked = intTotalChecked + 1
  11.       End If
  12.     End If
  13.  Next
  15. CountChecked = intTotalChecked
  17. End Function
Thanks in advance!
Oct 23 '12 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 10K+
P: 12,334
Please use code tags when posting code.

To get what you want, you'll have to either clone the recordset of the subform and loop through it and do your count that way or use a domain aggregate function like DCount() and passing in the same filter as the subform is linked on.
Oct 23 '12 #2

P: 2
Rabbit thanks for the quick reply!
Unfortunately I am new to access and vba. I have heard about cloning the recordset and using DCount(), but I have no idea where to start or how the vba would be written! Can you help?
Oct 23 '12 #3

Expert Mod 10K+
P: 12,334
You'll probably want to read through a VBA tutorial or take a class before you take on a project like this.

As for the DCount function, it's not VBA per se, you can look at Microsoft's documentation on it.
Oct 23 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.