?
Solved

Count Checkboxes which are ticked in a form/table/Column

Posted on 2003-03-23
5
Medium Priority
?
209 Views
Last Modified: 2008-03-06
I want to count all the checkboxes in a column which have been ticked.
I'v created a form, where the user will tick the checkbox, and then move on to the next record, now i want to get the total of the ticked checkboxes and display it on a form.
0
Comment
Question by:comicjoker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 8193364
Hello Comicjoker,

is this excel? since you mention column i presume the boxes are on a sheet? then this could help

Sub CountCheckedCheckboxes()
  Dim ws As Worksheet
  Dim objOLE As OLEObject
  Dim nNumChecks As Integer

  For Each ws In ThisWorkbook.Worksheets
    For Each objOLE In ws.OLEObjects
      If TypeName(objOLE.Object) = "CheckBox" Then
        If objOLE.Object.Value Then nNumChecks = nNumChecks + 1
      End If
    Next objOLE
  Next ws
  MsgBox nNumChecks
End Sub

HAGD:O)Bruintje
0
 

Author Comment

by:comicjoker
ID: 8193373
Its in Access, sorry I forgot to mention it.
0
 
LVL 44

Accepted Solution

by:
bruintje earned 600 total points
ID: 8193385
then you could try a little count function like this

Public Function CheckCount(frm as Form) AS Integer
     dim ctl as control
    dim cc as integer

    for each ctl in frm.controls
        if typeof ctl is checkbox then cc=cc+1
    next

    CheckCount=cc
End Function

place it in a module and call it when you need to display it on a label on your form
0
 

Author Comment

by:comicjoker
ID: 8194433
What I did, was create a Query, with all the check boxes marked true. Then created a form based on the query, placed an edit box and in the control source typed ( =Count(*) ) which basicaly counts all the records in the query
0
 
LVL 44

Expert Comment

by:bruintje
ID: 8196308
:) that's a solution too ... thanks for the grade
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

777 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