RecordsetClone object can be referenced and manipulated as shown in my code sample.
RecordsetClone object can be referenced and manipulated as shown in my code sample.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Using June7's method, which is better because, as he said, it covers all RecordSets, even if it's a Filtered RecordSet:
To tick all
Code:Private Sub cmdTickAllBoxes_Click() Dim rs As DAO.Recordset Set rs = Me.RecordsetClone With rs .MoveFirst Do While Not rs.EOF .Edit !CheckboxFieldName = -1 .Update .MoveNext Loop End With rs.Close Set rs = Nothing Me.Requery End Sub
To untick all
Code:Private Sub cmdUntickAllBoxes_Click() Dim rs As DAO.Recordset Set rs = Me.RecordsetClone With rs .MoveFirst Do While Not rs.EOF .Edit !CheckboxFieldName = 0 .Update .MoveNext Loop End With rs.Close Set rs = Nothing Me.Requery End Sub
To do both with a single button
- Create a Command Button
- Name it cmdTickUntickAllBoxes
- Set it's Caption to Tick All
Code:Private Sub cmdTickUntickAllBoxes_Click() Dim rs As DAO.Recordset Set rs = Me.RecordsetClone If cmdTickUntickAllBoxes.Caption = "Tick All" Then cmdTickUntickAllBoxes.Caption = "Untick All" With rs .MoveFirst Do While Not rs.EOF .Edit !CheckboxFieldName = -1 .Update .MoveNext Loop End With rs.Close Set rs = Nothing Me.Requery Else cmdTickUntickAllBoxes.Caption = "Tick All" With rs .MoveFirst Do While Not rs.EOF .Edit !CheckboxFieldName = 0 .Update .MoveNext Loop End With rs.Close Set rs = Nothing Me.Requery End If End Sub
Linq ;0)>
I renamed an existing command button and changed the caption, copied the third example over the VBA code already there after changing CheckboxFieldName to Profiles. Clicked and nothing happened. Should I see check marks?
If you renamed the button did you rename the procedure in the Sub line?
Always more than one way to accomplish same result. Another option to tick/untick all:
CurrentDb.Execute "UPDATE tablename Set Profiles=" & IIf(Me.cmdTickUntickAllBoxes.Caption = "Tick All", True, False)
Me.cmdTickUntickAllBoxes.Caption = IIf(Me.cmdTickUntickAllBoxes.Caption = "Tick All", "Untick All", "Tick All")
Last edited by June7; 06-20-2014 at 08:21 PM.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.