?
Solved

Count checked checkboxes

Posted on 2008-01-30
4
Medium Priority
?
1,163 Views
Last Modified: 2013-11-28
Hello,

On my MS Access form I'm creating an Unbound textbox which I'd like to count the number of check boxes selected in a subform (default view "DataSheet"). I thought if I do =Sum([table].[checkbox])*-1 would work, but that is not the case.

how can I accomplish this?
0
Comment
Question by:AIdoHSG
4 Comments
 
LVL 20

Assisted Solution

by:clarkscott
clarkscott earned 400 total points
ID: 20780588
You have to query the record and COUNT the checkboxes that = true (or not zero).

Scott C
0
 
LVL 11

Accepted Solution

by:
fanopoe earned 800 total points
ID: 20780856
This should work behind am event handler:

    Dim ctl As Control
    Dim i As Integer
    i = 0
    For Each ctl In Me.YourSubFormName.Controls
        If ctl.ControlType = 106 Then 'The control is a checkbox
            If Nz(ctl.Value, 0) = -1 Then 'do not evaluate null or unchecked
                i = i + 1
            End If
        End If
    Next
   
    Debug.Print i <------Use this however you need it
0
 
LVL 2

Assisted Solution

by:kiprimshot
kiprimshot earned 800 total points
ID: 20780941
Im not sure this will work for the Datasheet view...but this is what I would do in a regular form.

Dim ctl As Control
Dim intCount As Integer
intCount = 0

For Each ctl In Controls

If TypeOf ctl Is CheckBox Then
    If ctl.Value = -1 Then
        intCount = intCount + 1
    End If
End If


Next

MsgBox intCount
0
 

Author Closing Comment

by:AIdoHSG
ID: 31426507
Thank you all... I managed to get it to work.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question