Togglebuttons in a Userform.

P

PaulW

My userform has 2 togglebuttons. Both should clear checkboxes 1-4, and enable
these checkboxes if the togglebutton is "on", or disable if the togglebutton
is "off".

This is working great so far. and this is probably only a little thing, but
when I click one of the buttons to "On", I want the other to revert to "Off".

I had it on _change() instead of _click() but the problem was still the
same. If one of the buttons is set to "on" and I click the other it will
indeed reset the first to "off", but thats all it does. The frame and
checkbox Disable and the button isn't clicked "on". I also tried moving the
part about changing togglebutton1 to false to the top, but doesn't seem to
help.

It appears that the macro is triggering because you click on the box, but
its not switching it on on the first click for some reason?

Private Sub ToggleButton2_click()

With Frame1
.Enabled = ToggleButton2.Value
End With

With CheckBox1
.Value = False
.Enabled = ToggleButton2.Value
End With

With ToggleButton1
.Value = False
End With

End Sub
 
P

PaulW

Nevermind, adding

If ToggleButton2.Value = False Then ToggleButton1.Value = True

seems to sort it.
 
S

Susan

here's some (UNTESTED) ideas:

Private Sub ToggleButton2_click()

ToggleButton1.Value = False 'might need Me.ToggleButton1
'rest of code to do whatever

End Sub

and then,
Private Sub ToggleButton1_click()

ToggleButton2.Value = False 'might need Me.ToggleButton1
'rest of code to do whatever

End Sub

OR you could put an entirely different code set up in a general
module, to the effect of:

Private Sub ToggleButton2_click() 'either one
'put this in the userform code
ToggleButton1.Value = False
Call Change_other_toggle
'rest of code to do whatever

End Sub

sub Change_other_toggle
'put this in the other module
if userform1.togglebutton1.value = true then
userform1.togglebutton2.value = false
userform1.checkbox1.enabled=false
userform1.checkbox2.enabled=false
'etc
end if

if userform1.togglebutton2.value=true then
userform1.togglebutton1.value=false
'enter other checkboxes to be disabled

end sub

hth
susan
 

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

Top