-
I know this is an easy one.
Please tell me what the right code is here.
For each (checkbox) in (form)
(checkbox).value = 0
Just to "turn off" all the checkboxes at once.
I know it's either this or a with statement but I don't remember it.
If you do, please post.
Thanks.
wengang
-
you could put all the check boxes into a control array and make it very easy:
Code:
For i = 0 To Check1.Count - 1
If Check1(i).Value = 1 Then
Check1(i).Value = 0
Else
Check1(i).Value = 1
End If
Next i
this alternates the status of each checkbox.
-
Thanks
but the code i'm looking for is along these lines
Dim fCheckbox As Checkbox
For Each fCheckbox In frmMain
fCheckbox.Value= 0
Next
This code doesn't work obviously, so does anybody know how to repair it?
-
this does it without having an array
Code:
For i = 0 To Form1.Controls.Count - 1
If TypeOf Form1.Controls(i) Is CheckBox Then
If Form1.Controls(i).Value = 0 Then
Form1.Controls(i).Value = 1
Else
Form1.Controls(i).Value = 0
End If
End If
Next i
it alternates the value of every checkbox on the form
-
yet another way:
Code:
On Error GoTo ErrHandler:
For Each CheckBox In Me.Controls
If CheckBox.Value = 0 Then
CheckBox.Value = 1
Else
CheckBox.Value = 0
End If
Next CheckBox
ErrHandler:
i think this was along the lines you were thinking, but all of my examples work :)
so, how's this one?
-
Thanks a lot David. I never lost confidence in you.
But, it was the second example that worked for me.
The third one (for whatever reason) sends out the error 'Object doesn't support this property or method'
Anyway, i appreciate it. That will make my "Reset" key a lot faster to code in the future.
-
well, i got there in the end,
i don't know why the third one didn't work, it worked for me