Code to clear all CheckNBoxes when a Form loads

  • Thread starter Thread starter ryguy7272
  • Start date Start date
R

ryguy7272

I have 20 CheckBoxes on a Form. All are set to Triple State = No. When the
Form opens, all CheckBoxes, except one, always has a solid green square in
the middle. I check off all CheckBoxes, close the Form, and all will have
the tiny green square in there again. Is there some setting that manages
this? If not, can I add a snippet of code to clear all CheckNBoxes when the
Form loads?

Thanks!
Ryan---
 
I'm not sure why they're acting like that, but you can probably run through
them in an open event and set them to false...

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
ctl = False
End If
Next


I think that would effectively all the check boxes to false, though I have
no idea why they would do that to begin with.
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Thanks for the code, Jack! It worked perfect!! I have no idea why it is
doing this, but when I opened the form this morning, same thing. I popped
your code in there, closed it and opened it, and now it works like a normal
form.
 
Strange though.... I don't like it. Like fixing an oil leak by dumping more
oil in instead of plugging the leak. I can't image what might be causing it
to begin with...

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Hi again Ryan,
I can explain you the behaviour of your check boxes.
I think that all except 1 are unbound so when you open the form access don't
know the value to give to the various check boxes. If you set a default value
in the properties of the check boxes (0=unchecked, -1=checked) you'll fix it.
Perhaps also the check box that's not dimmed when you open the form is
unbound but you setted for it a default value.

HTH Paolo
 
You were exactly right Paolo! I corrected the discrepancy and commented out
the code because I don't want code running but I do want to keep it for
future use as I can foresee that coming in handy in some other project some
day.

Thanks guys!!
 
Back
Top