Link to home
Start Free TrialLog in
Avatar of leezac
leezac

asked on

Loop to Select Checkboxes

I am using this code to select all checkboxes on a form. My question is - Is it the best way?
I find that it may skip a check box and is not consistant.

Private Sub Command31_Click()
Dim rst As DAO.Recordset, i As Integer

Set rst = Me.RecordsetClone
i = 0
rst.MoveFirst
Do While Not rst.EOF
   i = i + 1
   rst.Edit
   If rst![Excluded] Then
       rst![Excluded] = False
   Else
       rst![Excluded] = True
   End If
   rst.Update
   rst.MoveNext
Loop
MsgBox i & " Records Marked."

rst.Close
Set rst = Nothing
End Sub
Avatar of mbizup
mbizup
Flag of Kazakhstan image

<< select all checkboxes on a form.>>

Are you trying to mark all as true?  Your code is not doing that.

Or are you trying uncheck checkboxes that are checked and check checkboxes that are unchecked?  (That is what your code currently seems to be doing).
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leezac
leezac

ASKER

Thank you!  That works better.