none
Access 2016 Option Buttons RRS feed

  • Question

  • I found the below code to clear all selections for checkboxes on a form. I had to add another checkbox on the form and now the code does not work.  I am extremely new to Access 2016 and vba.  Any assistance to get both checkboxes to clear on one form is appreciated.  

    Private Sub Command91_Click()

    With Me.RecordsetClone
       .MoveFirst
       Do While .EOF = False
          .Edit
          .Select("IsSelected") = False
          .Update
          .MoveNext
       Loop
    End With
    End Sub

    Friday, October 11, 2019 8:31 PM

All replies

  • .Select("IsSelected") = False

    Are you sure??? I have never seen this syntax. 


    -Tom. Microsoft Access MVP

    Friday, October 11, 2019 8:44 PM
  •       .Select("IsSelected") = False
    Assuming that IsSelected is the name of a column of Boolean (Yes/No) data type to which the check box in the form is bound, the line to set the value to False for all rows would be:

        .Fields("IsSelected") = False

    To do the same for another Boolean column repeat the line, changing the name of the column in parentheses to the other column's name.


    Ken Sheridan, Stafford, England

    Saturday, October 12, 2019 5:33 PM
  • You might be able to use the following Public Function to select and clear (sets value to 0) all Check boxes on any open form. Copy the following Public Function into any module.

    Public Function ClearForm()
    On Error GoTo ClearForm_Error
    Dim Frm As Access.AccessObject

    Dim Selected As Form
    For Each Frm In Application.CurrentProject.AllForms
        With Frm
           If .IsLoaded Then
               DoCmd.SelectObject acForm, Frm.Name
               'MsgBox Frm.Name
                Set Selected = Screen.ActiveForm
                With Selected
                    Dim ActiveCntrl As Control
                    For Each ActiveCntrl In Selected.Controls
                        If ActiveCntrl.ControlType = acCheckBox Or ActiveCntrl.ControlType = acOptionGroup Then
                            'MsgBox ActiveCntrl.Name
                            ActiveCntrl = 0
                        End If
                    Next
                End With
               End If
        End With
    Next

    Exit Function

    ClearForm_Error:

    DoCmd.CancelEvent
    Resume Next
    Exit Function
    End Function

    1. Open the form in design mode
    2. Insert a Command Button
    3. Click the Event tab on the Properties window
    4. Create an Event Procedure on the buttons On Click Event
    5. Type in Call ClearForm in the VBA window

    Please note:

    This will set Check Boxes NOT associated with an Option Group AND Option Groups to 0 (Nothing checked)


    Saturday, October 12, 2019 5:37 PM
  • not sure if the control being discussed is a checkbox or an option group

    but am wondering if a loop is even needed; at the event one can simply list the control and set its value:

    me.checkbox1=0

    me.optiongroup2=0    or possibly =Null

    I suppose if the form contain a great quantity of controls that a loop would maybe be easier coding - but

    Tuesday, October 15, 2019 10:06 PM