Setting ToggleButton Value

  • Thread starter Thread starter fazstp
  • Start date Start date
F

fazstp

Is there a way to set the value of a toggle button without triggering a
click event? I have a set of three buttons that I want to deselect the
other two options when any one is selected.

ie.
Private Sub ToggleButton1_Click()
ToggleButton1.Value = True
ToggleButton2.Value = False
ToggleButton3.Value = False
End Sub

When I set the value of the other two it seems to trigger a click event
on them as well.

I have tried the example of exclusive toggle buttons on ms site
(http://support.microsoft.com/?kbid=213714) but couldn't get it to
work. It seemed to save all the calls to the sub until I closed the
form.
 
You can add a public variable, set it to something, check it and then have each
_click event check that variable:

Dim blkProc as boolean

Private Sub ToggleButton1_Click()
blkproc = true
ToggleButton2.Value = False
ToggleButton3.Value = False
blkproc = false
End Sub

Private Sub ToggleButton2_Click()
if blkproc = false then exit sub
'existing code here
End Sub

I'm not quite sure why you would be setting button1 to true in the
togglebutton1_click event, though.
 
Thanks for that. That did the trick. The reason for setting the state of
the clicked button to True is so that there is always at least one
button selected, otherwise clicking the already selected option leaves
all buttons deselected.
 
Can you have two groups of three optionbuttons on one form (ie.
selecting one of three options for two different variables)?
 
Sure. One property of an ActiveX (control toolbox toolbar) optionbutton is
the groupname.

Pick any name and assign it to each of the first three (first group). Pick
any other name and assign it to each of the next three.

You can also put two frames on the Userform, then put 3 optionbuttons in
each.
 
Back
Top