One to Many Checkbox

  • Thread starter Thread starter Stephen
  • Start date Start date
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
 
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
 
Back
Top