Check uncheck all checkboxes

G

Guest

please, help me to create checkbox on the for that will check/uncheck 20
other checkboxes on the same form.
 
D

Douglas J. Steele

Won't it make more sense to use a button, not another checkbox?

Assuming you're going to uncheck every checkbox on the form, you need code
like:

Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If TypeOf ctlCurr Is Checkbox Then
ctlCurr = False
End If
Next ctlCurr

If you ARE going to use a checkbox to kick this off, you'll probably want to
not uncheck the "trigger" checkbox, so you'd have something like:

Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If TypeOf ctlCurr Is Checkbox Then
If ctlCurr.Name <> "chkUncheckAll" Then
ctlCurr = False
End If
End If
Next ctlCurr

If there are other checkboxes you don't want to impact, you'll need to come
up with some other way of identifying those checkboxes that you do want to
clear. One approach is to set the Tag property of those that you want to be
able to clear. Put something like "Clear" in that property, and use code
like:

Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If TypeOf ctlCurr Is Checkbox Then
If ctlCurr.Tag = "Clear" Then
ctlCurr = False
End If
End If
Next ctlCurr
 
G

Guest

Put the following in the first check box's AfterUpdate event procedure:

Dim ctrl As Control

For Each ctrl In Me.Controls
If ctrl.ControlType = acCheckBox Then
ctrl = Me.ActiveControl
End If
Next ctrl
 
G

Guest

works perfectly, thanks

Ken Sheridan said:
Put the following in the first check box's AfterUpdate event procedure:

Dim ctrl As Control

For Each ctrl In Me.Controls
If ctrl.ControlType = acCheckBox Then
ctrl = Me.ActiveControl
End If
Next ctrl
 

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