Dynamically enable combo box if check box is checked

G

Guest

I have a userform with multiple combo boxes. I also have a check box as a
response to a question on the form. If checked, I would like the combo box
for the next question enabled. By default, I want the same combo box
disabled. How do I do this dynamically? Thanks!

Mark
 
S

Susan

in your userform_initialization sub, add

combobox6.enabled=false '<-- change to your combobox

then in your userform coding, you would add something like

private sub checkbox4_click() '<-- change to your checkbox
combobox6.enabled=true
end sub

so when checkbox4 is clicked (or "checked"), combobox6 automatically
becomes enabled.

hth!
susan
 
G

Guest

Thanks! That works great--how do I get it to disable the combobox if the
checkbox is unchecked again? Right now, the combobox enables when the
checkbox is checked, but stays enabled if the checkbox is clicked again...
 
S

Susan

hmmmm.
for that you'll need to add a boolean value, so the macro can tell if
it's being "checked" or "unchecked" - it only notices "clicked".

in your initialization sub, add

dim myBoolean as boolean

myBoolean=true


then in
private sub checkbox4_click()
if myboolean=true then
combobox6.enabled=true
myboolean=false
else
combobox6.enabled=false
myboolean=true
end if
end sub


1. so - userform opens - boolean value is true.
checkbox is checked the first time - combobox becomes enabled, boolean
value is set to false.

2. 2nd time checkbox is triggered, it runs thru the same private sub,
but this time the boolean value is NOT true, so it skips the 1st part
of the if statement. since boolean value is false, the 2nd part of
the if statement kicks in, dis-enabling the combobox & changing the
boolean back to true.

3. if it gets checked a 3rd time, it goes back to #1 above.

:)
susan
 
G

Guest

Nevermind--I figured it out.

Thanks!

MAWII said:
Thanks! That works great--how do I get it to disable the combobox if the
checkbox is unchecked again? Right now, the combobox enables when the
checkbox is checked, but stays enabled if the checkbox is clicked again...
 
G

Guest

checkbox4.value is boolean (true or false), when ".value" left off, checkbox4
defaults to it's value. I know, it's kind of terse, but it works.

The click event occurs whether the checkbox is click to be "on" or clicked
to be "off". This code just makes use of the checkbox property ".value".
 
G

Guest

I used the following...

Private Sub checkbox1_click()

If checkbox1.Value = False Then
combobox1.Enabled = False
Else
combobox1.Enabled = True
End If

End Sub

Seemed a lot easier to me and I figured it out shortly after the request.
It does the trick. Thanks for the help!

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top