sirbounty
asked on
check all checkboxes
This doesn't seem to be working for me...what am I missing?
Dim ctl As CheckBox
For Each ctl In Controls
ctl.Checked = True
Next
Dim ctl As CheckBox
For Each ctl In Controls
ctl.Checked = True
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When you use Me.Controls, you iterate ALL controls directly contained by the form. What if you have controls on your form that are not CheckBoxes? This would cause an error since your code would attempt to convert say a TextBox to a CheckBox in your For...Next loop!
You are correct about the CType() function. It is converting the "ctl" variable to a CheckBox if it passed the "TypeOf ctl Is CheckBox" test (which returns True if "ctl" is a CheckBox).
You are correct about the CType() function. It is converting the "ctl" variable to a CheckBox if it passed the "TypeOf ctl Is CheckBox" test (which returns True if "ctl" is a CheckBox).
ASKER
The way I read it was
Declare a variable as a checkbox control. Now loop through all of those 'type' controls, not 'all' controls.
I guess it sort of makes sense, I just presumed that by declaring the ctl as a specific checkbox that that would/should limit the iteration to those types of controls only...
Thanx for the follow.
Declare a variable as a checkbox control. Now loop through all of those 'type' controls, not 'all' controls.
I guess it sort of makes sense, I just presumed that by declaring the ctl as a specific checkbox that that would/should limit the iteration to those types of controls only...
Thanx for the follow.
Don't feel bad, your assumption is a pretty common one and the type of code you posted comes up on EE quite a bit. =)
ASKER