Checkbox Loop/For Next

C

carljonas

Perhaps a to simple question. However I´m lost and I´m unable to find
guidance through older postings here. Here´s the prerequisite: I have
a command button in a form. With a single button click I want to loop
through all records in a table/form and uncheck every checked
checkbox. Here´s my start up code:

Dim Counter As Integer

For Counter = 1 To ' End of records; unsure of correct code
If Val = True Then
Val = False
End If
Next Counter
End Sub

For example if i put the first line as 'For Counter =1 to 10' then
the first record is unchecked, however the code does not uncheck the
rest. Any advice on this seemingly easy task would be appreciated.

//Jonas
 
M

Marshall Barton

Perhaps a to simple question. However I´m lost and I´m unable to find
guidance through older postings here. Here´s the prerequisite: I have
a command button in a form. With a single button click I want to loop
through all records in a table/form and uncheck every checked
checkbox. Here´s my start up code:

Dim Counter As Integer

For Counter = 1 To ' End of records; unsure of correct code
If Val = True Then
Val = False
End If
Next Counter
End Sub


If you want to set a field for eery record in a table:

CurrentDb.Execute "UPDATE
Set [Val] = False "_
"WHERE [Val] = True"

If you want to limit the change to just the filtered records
on a form:

With Me.RecordsetClone
.MoveFirst
Do Until .EOF
If ![Val] Then ![Val] = False
.MoveNext
Loop
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top