UserForm Checkboxes

  • Thread starter Thread starter MWE
  • Start date Start date
M

MWE

1. CheckBox Size: I have several checkboxes that are
identical in height and width, and spaced uniformly within
a frame. The actual size of the checkbox "box" varies
slightly from one to the next. The size differences are
small but noticeable. Further the size and "darkness"
(probably change in font size) of the checkmark (when the
box value is true) varies as well, some are smaller
and "light" and some are larger and "dark". I have
fiddled around with heights (making them all one or two
points larger or smaller), locations, etc., but can not
get the boxes to be the same size. What am I doing wrong
here?

2. CheckBox communications: I have several checkboxes in
a frame. I want to limit the user to one selection. Thus
if box 1 is selected (value = True), boxes 2, 3 and 4
should automatically have values = False. How is this
done?
 
Private Sub Userform_Initialize()
for each ctrl in Userform1.Frame1.controls
if typeof ctrl is MSforms.Textbox Then
ctrl.Heigth = Userform1.Controls("checkbox1").Height
ctrl.Width = Userform1.Controls("Checkbox1").Width
ctrl.Left = Userform1.Controls("Checkbox1").Left
end if
Next
End Sub

for item 2, use optionbuttons - that is what they do by default.
 
2. CheckBox communications: I have several checkboxes in
a frame. I want to limit the user to one selection. Thus
if box 1 is selected (value = True), boxes 2, 3 and 4
should automatically have values = False. How is this
done?
Why not use option buttons?
 
the option buttons work; thanks. But now I have the same
problem with size of the option buttons that I had with
the checkboxes. Your code does not do anything different
than what I had already done manually, i.e., it sets each
height and width equal to the same value. Whether I use
your code (which I tried) or do it manually, I get the
same results, i.e., there are box-to-box or button-to-
button size differences. I am using the default size
(height and width) for both boxes and buttons.
 
I did have two typos, one of which reference the size to textbox1 instead of
checkbox1.

Private Sub Userform_Initialize()
For Each ctrl In UserForm1.Frame1.Controls
If TypeOf ctrl Is MSforms.CheckBox Then
ctrl.Height = UserForm1.Controls("checkbox1").Height
ctrl.Width = UserForm1.Controls("Checkbox1").Width
ctrl.Left = UserForm1.Controls("Checkbox1").Left
End If
Next
End Sub

worked fine for me. All the check boxes were the same height and width -
although it didn't correct the spacing between checkboxes - but that wasn't
part of the question.

I am not sure how they can have the same height and width and exhibit the
differences you describe.
 
I saw that mistake as I was trying the code. I also
inserted debug statements to make sure the If statement
was triggering correctly. The "before" values for height
and width and the "after" values are the same. And the as
displayed sizes fo the boxes or buttons varies.
 
I have found a partial solution to the problem with checkboxes o
optionbuttons appearing as different sizes even though the propertie
(height, width, font, etc) were identical. It turns out that th
spacing between boxes or buttons has some influence on box/button size
In my particular case, the box/button HEIGHT is 18. I found that th
spacing between TOPs of sequential objects must be 22 or more. If les
than 22, some elements were undersized but I could find no pattern t
what happens. In some cases, frames with 2 elements did not care abou
spacing – anything worked. In other two element frames, spacing wa
critical. Same for 3, 4, and 5 element frames. My sense is that ther
is an underlying grid that forces elements to be in certain places an
will adjust element size to accommodate the grid. *This is probably
screen resolution issue.* When I have a few minutes, I will fiddl
with spacing and screen resolution and see what that doe
 
Back
Top