Mdaox
Mdaox

Reputation: 81

How can I uncheck an entire column of checkboxes?

How can I uncheck an entire column of checkboxes? I have a field in each record in my access table that has a checkbox, as time goes on I check boxes, but at the end to reset I would like to put a button on the split form that will uncheck all of the boxes.

It is the second field "Acct" on the table "tblData1" and I want to control it from the form "frmMain" Using a button "cmdResetAcct"

Thank you in advance!

Upvotes: 2

Views: 1950

Answers (2)

Gustav
Gustav

Reputation: 55981

You can use the recordset you already have directly in the OnClick event of your button:

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
If rs.RecordCount > 0 Then
    rs.MoveFirst
End If

While Not rs.EOF
    If rs!Acct.Value = True Then
        rs.Edit
            rs!Acct.Value = False
        rs.Update
    End If
    rs.MoveNext
Wend

Set rs = Nothing

This is very fast, and your form will update instantly.

Upvotes: 1

Andre
Andre

Reputation: 27644

Run an UPDATE query.

CurrentDb.Execute "UPDATE tblData1 SET Acct = False WHERE Acct <> False"

The WHERE clause makes it more efficient because only the checked rows are written.

Upvotes: 1

Related Questions