One to Many Checkbox

S

Stephen

I have a database in which there are checkboxes for each
state and then one for if all 48 states are included. Is
there any way that when the all 48 states checkbox is
checked subsequently all of the states checkboxes are also
checked? TIA
 
T

tina

here's the obvious, but long, way:

Private Sub AllStates_AfterUpdate()

If Me!AllStates Then
Me!Alabama = True
Me!Alaska = True
Me!Arkansas = True
(etc, etc, etc)
End If

End Sub

or, if the states' checkboxes are the ONLY checkbox
controls on that form, you could use the following code:

Private Sub AllStates_AfterUpdate()

If Me!AllStates Then
CheckAll
End If

End Sub

Private Sub CheckAll()

Dim ctlObject As Control

For Each ctlObject In Me.Controls
If TypeOf ctlObject Is CheckBox Then
ctlObject = True
End If
Next ctlObject

End Sub

fyi, if your form happens to include an OptionGroup
control that uses checkboxes, you'll need additional code
to trap the resulting error.

hth
 

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