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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recording information from multiple check boxes in to list

Status
Not open for further replies.

act2

Technical User
Dec 17, 2005
34
US
I have a form with 5 check boxes, the check boxes relate to answers the user must select. I would like to record the answers in a sub form list. I have the code so it will show if one of the check boxes is selected but not multiples. Not sure how I would do that.


Code:
Option Compare Database
Option Explicit
Private Sub cmdEnter_Click()


Dim ctl As Control
   Dim Ck As String
   
   For Each ctl In Me.Controls
      If ctl.ControlType = acCheckBox Then
      If ctl.Value = True Then
      
      

                Me.test = ctl.Controls(0).Caption
      
      Exit For
         End If
     End If

   Next


End Sub
 
Obviously, it's a bound subform?

I would use an insert statement, during each iteration, to whatever table the subform is bound to...


Private Sub cmdEnter_Click()


Dim ctl As Control
Dim Ck As String

For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
If ctl.Value = True Then

CurrentProject.Connect.Execute _
"INSERT INTO tblSubForm(fkID,txtAnswer,chkAnswer) " & _
"VALUES(" Me.pkID & ",'" & ME.txtAnswer & "'," & ctl.Value & ")"

End If
End If

Next


End Sub
 
Zion7 Thanks for your help, I ended up figuring out a different way:

Here’s my solution, which seems to work ok. Let me know if you see any pit falls doing it this way.

Thanks
Code:
Private Sub cmdEnter_Click()

Dim ctl As Control

   Dim i As Integer
   For i = 1 To 5
      
      For Each ctl In Me.Controls
         If ctl.ControlType = acCheckBox Then
            If ctl.Value = True Then
               
               Forms.frmMain.frmsubMain.Form.JobType = ctl.Controls(0).Caption
               
          End If
     End If
        Me.Refresh
            Forms.frmMain.frmsubMain.Form.Recordset.AddNew
    Next
  
     Exit For
    Next i

End Sub
 
No, looks good.
I like it!

...wish I thought of it myself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top