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
Microsoft Access

Avatar of undefined
Last Comment
leezac

8/22/2022 - Mon
mbizup

<< 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
mbizup

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
leezac

ASKER
Thank you!  That works better.
Your help has saved me hundreds of hours of internet surfing.
fblack61