Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set checkbox value No 1

Status
Not open for further replies.

MvP14

Technical User
Joined
Apr 14, 2003
Messages
13
Location
BE
I have a form based on a query. The form has a checkbox with default value No. The checkbox is used to filter a report (the user only prints the records where the value = Yes). I would like to add a button select all and a button deselect all.

Anyone out there able to help?
 
try this

Private Sub CheckAll_Click()
Dim ctl As Control
Dim intCount As Integer

For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
ctl = True
End If
Next ctl
End Sub

Private Sub UnCheckAll_Click()
Dim ctl As Control
Dim intCount As Integer

For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
ctl = False
End If
Next ctl
End Sub
 
The code works, but it only marks the current record and not all records. What should I add?
 
you may need to set the print if = yes to print if = true
 
That didn't do it. The problem seems to be that the command doesn't move to the next record to set the value of the checkbox to true/yes there and so on till all records have their checkbox changed.
 
try
Private Sub CheckAll_Click()
Dim ctl As Control
Dim intCount As Integer
Dim counter
Dim i
counter = DCount("test", "table1")
For i = 1 To counter
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
ctl = True
End If
Next ctl
DoCmd.GoToRecord , , acNext
Next i
DoCmd.GoToRecord , , acFirst
End Sub
 
test is a field in the table table1 to count number of records
 
Thank you very much. I used the query on which the form is based instead of the table on which the query is based so only the selected records' checkbox is changed.

I know I've taken a great deal of your undoubtedly important time already. The procedure works now, so it could end here. However, I permit myself to ask one more question (I'm very new to Access, so I hope I will be forgiven if this is all too impudent).

Now that I see the procedure work, it looks like there could be a more efficient solution. Is that so, and if so, what do you suggest?

If the question is indeed too impudent, forgive me and don't bother answering. My database works as it is, and it is thanks to you!

Thank you.
 
hehe i already thought of that

Private Sub Checkall_Click()
'make sure you have a check box on the form called checkall
'this assumes you have a field in you table with a yes/no box
Dim ctl As Control
Dim intCount As Integer
Dim counter
Dim i
DoCmd.GoToRecord , , acFirst
counter = DCount("question", "table1") 'question is a yes/no field in a tabel (table1) used to count records

For i = 1 To counter
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox And Me.CheckAll = True Then 'checkall is a checkbox on the form called checkall

ctl = True

End If
If ctl.ControlType = acCheckBox And Me.CheckAll = False Then
ctl = False

End If
Next ctl
DoCmd.GoToRecord , , acNext
Next i
DoCmd.GoToRecord , , acFirst
End Sub

this does it all from one little tick box on your form. follow the comments.

tell me if it works for you
 
or even nicer

Private Sub Checkall_Click()
'make sure you have a check box on the form called checkall
'this assumes you have a field in you table with a yes/no box
Dim ctl As Control
Dim intCount As Integer
Dim counter
Dim i
DoCmd.GoToRecord , , acFirst
counter = DCount("question", "table1") 'question is a yes/no field in a tabel (table1) used to count records

For i = 1 To counter
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then 'checkall is a checkbox on the form called checkall
Select Case Me.CheckAll
Case Is = False
ctl = False
Case Is = True
ctl = True

End Select
End If
Next ctl
DoCmd.GoToRecord , , acNext
Next i
DoCmd.GoToRecord , , acFirst
End Sub
 
It works just great for me. Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top