How to evaluate checkboxes with one routine?

Les M 0 Reputation points
2025-10-15T17:51:28.9533333+00:00

Referencing the screenshot below, I wanted to see how to make adjustments to the last checkbox (CLEAR ALL DATA).

Scenario: If I initially choose "CLEAR ALL DATA," then all other checkboxes are checked.
Then if I decided I want to uncheck one or more, for example, uncheck "Individual Grades," the
click change will uncheck the "Clear All Data" checkbox.

I was wondering if there was a way to accomplish this with one routine instead of having a click_change routine for each checkbox, i.e., regardless of which checkbox is unchecked, it triggers execution of a the same singular routine that will uncheck the "Clear All Data" checkbox if it is checked.

User's image

Microsoft 365 and Office | Development | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Tammy-Ng 4,525 Reputation points Microsoft External Staff Moderator
    2025-10-16T01:04:33.7966667+00:00

    Dear Les M
    Welcome and thank you for sharing your issues in the Q&A forum.

    Based on the information you provided, you require a more efficient programming method, using a single routine by assigning the same event handler to all relevant checkboxes. This single routine will check the status of the individual checkbox that was clicked to adjust the state of the "CLEAR ALL DATA" checkbox. This approach avoids the need to write multiple separate functions.
    To provide you with the best support, please confirm which application you are using (for example: Microsoft Access, Excel VBA). If the single routine solution does not work, please check the following three points again:

    • Do the checkbox names match the names used in the code?
    • Has the On Click event of all the data checkboxes been assigned to HandleDataSelectionChange?
    • Is the logic for the CLEAR ALL DATA checkbox working correctly (i.e., does it automatically select all other items when it is clicked)?

    Thank you for your cooperation. We look forward to assisting you further and resolving this matter promptly


  2. Les M 0 Reputation points
    2025-10-22T11:11:44.1533333+00:00

    Option 1 appears to be what I need but I am unsure of what triggers the execution of this code.

    Code reposted below. For clarity, Checkbox18 is the "Clear All Data" checkbox. Checkboxes 1-17 are the individual items. I have changed the references in the below code to reflect.

    Private Sub UpdateCheckAllStatus()
        ' Checks if all sub-checkboxes (1-17) are checked and updates CheckBox1.
        
        Dim i As Integer
        Dim AllChecked As Boolean
        AllChecked = True ' Start by assuming all are checked
        
        ' Loop through CheckBox1 to CheckBox17
        For i = 1 To 17
            ' Use Me.Controls() for UserForm or SheetName.Controls() for Worksheet ActiveX
            If Me.Controls("CheckBox" & i).Value = False Then
                AllChecked = False
                Exit For ' Optimization: Stop checking once one is found unchecked
            End If
        Next i
        
        ' Update the main Checkbox (Checkbox18) status
        Me.CheckBox18.Value = AllChecked
    End Sub
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.