Looping through Checkboxes

  • Thread starter Thread starter saje
  • Start date Start date
S

saje

Guest
I need to loop through all the checkboxes on a form and determine if they are checked. If they are, then I'd like to retrieve the name of the checkbox and the caption of its attached label. Here's the code I have so far which isn't working: (I'm running Acc 2000)

Private Sub cmdNext_Click()
Dim ctl As Control
Dim NewField As String
Dim NewField2 As String
Dim frm As Form
Set frm = Forms!frmMaint

For Each ctl In frm.Section(acDetail).Controls
If ctl.ControlType = acLabel Then
If ctl.Parent = True Then ('Error occurs at
this line)
NewField = ctl.Caption
NewField2 = ctl.Parent.Name
End If
End If
Next ctl
End Sub

The code above produces runtime error 450, Wrong Number of Arguments or Invalid Property Assignment. If I put .Value after 'Parent' then I get error 2465, Application-defined or object-defined error.

I've also tried the code below and get runtime error 438, "Object Doesn't support this property or method."

For Each ctl In frm.Section(acDetail).Controls
If ctl.ControlType = acCheckBox Then
If ctl.Value = -1 Then
NewField = ctl.Label.Caption ' (Error occurs on this line. I also tried just ctl.Caption and get the same error)
NewField2 = ctl.Name
MsgBox (NewField2)
End If
End If
Next ctl

Thanks in advance--any help will be appreciated!

Susan
 
Try to use this code:
If Ctl.Parent.Value = True Then

Thanks a lot, reading your code new ideas born im my mind. Bye, S.
 

Users who are viewing this thread

Back
Top Bottom