Counting Checkboxes.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Can a control on a form display a counter for the number of checked items on a subform? I have a form with a counter on it. The subform is in datasheet view and one field is a checkbox. There are two things I want to do

1) As user ticks a checkbox, the counter on the main form increments; also if user 'unchecks' a box, the counter decrements
This counter should be updated live

2) I have 2 radio buttons on the Main Form (btnSelectAll) and( btnDeselect All) that do as they are named. Sometimes the # records displayed is 200+ and would be tedious to check off each one individually. The counter should total here too

Thanks in advance, People

Wil
 
Sum the yes no field. Access uses -1 for True, and 0 for False. Summing
therefore gives the negative count of the Yes values.

1. Open the subform in design view.

2. If you do not see a Form Footer section, select Form Header/Footer from
the View menu.

3. Add a text box to the form footer section, and give it these properties:
Name txtCount
ControlSource =-Sum([NameOfYourYesNoFieldHere])

4. Save. Close.

5. Open the main form in design view, and add a text box with Control
Source:
=[NameOfYourSubformControlHere].[Form].[txtCount]

The text box count will update when you save the subform record.

To select/deselect all related records

Private Sub btnSelectAll_Click()
Dim strSql As String
If Not Me.NewRecord Then
strSql = "UPDATE [NameOfYourSubformTableHere] SET
[NameOfYourYesNoFieldHere] = True WHERE ([NameOfYourYesNoFieldHere] =
False) AND ([NameOfYourForeignKeyFieldHere] = " &
Me.[NameOfYourMainFormsPrimaryKeyHere] & ");"
dbEngine(0)(0).Execute strSQL, dbFailOnError
Me.[NameOfYourSubformControlHere].Form.Requery
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Will said:
Can a control on a form display a counter for the number of checked items
1) As user ticks a checkbox, the counter on the main form increments; also
if user 'unchecks' a box, the counter decrements.
This counter should be updated live.

2) I have 2 radio buttons on the Main Form (btnSelectAll) and( btnDeselect
All) that do as they are named. Sometimes the # records displayed is 200+
and would be tedious to check off each one individually. The counter should
total here too.
 
Back
Top