473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Calculate number of true checkboxes in Continuous Form

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
  2.  
  3. Dim intTotalChecked As Integer
  4. Dim ctl As Control
  5.  
  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
  14.  
  15. CountChecked = intTotalChecked
  16.  
  17. End Function
Thanks in advance!
Oct 23 '12 #1
3 3617
Rabbit
12,516 Expert Mod 8TB
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
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
Rabbit
12,516 Expert Mod 8TB
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

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

Similar topics

3
by: Pat | last post by:
Hello, I've used Sum() to total bound fields on a continuous form with no problem. However, I now have a continuous form, on which I use an unbound field to calculate the number of hours between...
1
by: D Boyd | last post by:
Im trying to get the name of a bound control on a continuous form in Access. So that I can get the value of any text field. This is what Im looking to do.... The user enters a value for number...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
2
by: bobh | last post by:
Hi All, In Access97 I have a form setup as a continuous form several of the bound controls have calculations that are done in the 'after update' event via VBA code and all works fine. My...
1
by: Michael R | last post by:
Hello. I have a rather simply question - how to display a line number in an empty control of a continous form? I can't use totals query for that form. Thanks, Michael.
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
3
by: trgpham | last post by:
Hi all, I have a question and really hoping you guys can help or point me to the right direction. MY SCENARIO: I need to design a screen which show up all the questionnaires and the users can...
4
by: jtertin | last post by:
I want to put a button on a continuous form. I would like the value of the button to represent the iteration number of the form. For example, if a form iterates (continues) for 10 records in a...
8
by: ladybug via AccessMonster.com | last post by:
I have a table that has three fields. First is date, Second is a text field, the third is a number. I want to create a form where the date is entered at the top and then the text field and...
3
by: AdamOnAccess | last post by:
This is something I've always had trouble with, and it comes up fairly frequently... I have a continous form with a single text field and next to this text field, I have a caption that maintains...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.