Hi, Ezekiel.
I'm still confused as to the purpose of this database. If it is to store
the responses of multiple people to a set of questions, then my first
impression is that is not normalized. A many-to-many relationship seems to
exist between Respondants and Responses, that would normally be implemented
through 2 1-to-many relationships.
A checkbox can either be bound to a boolean or a numeric field such that it
stores
-1 when it's checked and 0 when unchecked, or it can be unbound. Although
I'm still not clear on what you're trying to do, my guess is that you want to
insert records in table 2 for every box on the form that is checked, and that
you want to prohibit the user from checking more than 5 boxes.
If this is the case, I think the way to implement it is to either use a
series of unbound checkboxes and a "Store Answers" command button. When
pressed, loop through the form controls, adding up the number of responses.
If it totals more than five, display a message and return the user to the
form, otherwise, repeat the loop and insert a record based on whether it's
checked or not. There are more sophisticated algorithms to implement this,
but since the number of passes is small, it won't make a hill of beans
difference.
You can use the Tag property of each checkbox control to store the
appropriate value to be inserted.
' Command button OnClick event procedure
Dim ctl As Control
Dim intCheckCount As Integer
' Initialize counter
intCheckCount = 0
' Count up check boxes
For Each ctl in Me.Controls
If ctl.ControlType = acCheckBox Then
If ctl.Value = True Then
intCheckCount = intCheckCount + 1
End If
End If
Next ctl
If intCheckCount > 5 Then
MsgBox ("Please check only five boxes")
Me!ControlNameToPlaceCursor.SetFocus
Exit Sub
End If
' Insert records
For Each ctl in Me.Controls
If ctl.ControlType = acCheckBox Then
If ctl.Value = True Then
' SQL Insert statement here including reference to ctl.Tag
End If
End If
Next ctl
Hope that helps, but if I'm way off base on what you're trying to do, please
post a generic description of the database's purpose, and what the form looks
like.
Sprinks