Counting Check Boxes

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Can I get count of checkboxes on a continuous form whose value is True
(checked) on a form footer?

TIA

Paul
 
I have not done this before, so this is a theory supported by air code.
Basically, to get the count, I would suggest using th DCount() function. To
ensure you count the correct records, your criteria argument for the DCount
will have to be exactly the same as the filtering or criteria that returns
the records for the form plus identify to count only when the check box is
checked (True). Then to update the count, you will need to use the After
Update event of the check box on the form.

Me.txtTotalChecked = Nz(DCount("*", "MyTableName", "[ChkField] = -1 And " _
& <add the criteria to select the records here>)

Now, what I am not certain of is when records are updated in a continuous
form. That is because I have never used one. If they behave like a single
form, then they are updated when you move to a different record. This could
mean that the check box you click may not be included in the count because
you have changed the value, but not moved off the record. I would experiment
with it to see if there is a discrepency. If this is the case, you could
force the record to update before you do the count:
Me.Dirty = False
Will update the record iif a change has ben made to the table.

Let me know it this works.
 
1) create a texbox in your form footer. Assume its name is "MyTextBox"
2) in the OLoad event of you rform add this code:

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open Me.RecordSource, CurrentProject.Connection, adOpenStatic,
adLockReadOnly
With rst
.Filter = "<nameofthefieldthecheckboxisboundedto>=1"
Mytextbox.value= .RecordCount
End With
End Sub

Hope ti help
 
Klatuu:
I had a similar problem, your posting helped me to discover the solution.
In Access 2003, I put a text box in the footer of my form with the following
(using aircode):
=DCount("*","YourTable","YourCheckBox=-1")
"YourTable" is the table that this form views.

I then went to the YourCheckBox field on the form and in the AfterUpdate
event added the following:
Me.Requery

It works like a charm... as soon as I check or uncheck a record, the count
field increases or decreases as appropriate.

Thanks for your help!
 
Back
Top