Why wont this code work?

M

Mark Stephens

I'm trying to get the effect of a push button radio so only one at oce will
be pushed (ie all the others pop out if one is pressed).

Strange thing is, if I go into design mode and run the code from within VB
by say clicking on toggle button 1 and then step through it, it works!

Maybe there's an easy way of doing this (grouping them) it seems to be the
way most people would want to use them (like option buttons?). Any help much
appreciated; stuff like this sucks up your time and attention so you can't
do what you need to.

Private bBlockEvent As Boolean

Private Sub ToggleButton1_Click()

If bBlockEvent = True Then Exit Sub

If ToggleButton2 = True Then
bBlockEvent = True
ToggleButton2 = False
End If
If ToggleButton3 = True Then
bBlockEvent = True
ToggleButton3 = False
End If
If ToggleButton4 = True Then
bBlockEvent = True
ToggleButton4 = False
End If
If ToggleButton5 = True Then
bBlockEvent = True
ToggleButton5 = False
End If
If ToggleButton6 = True Then
bBlockEvent = True
ToggleButton6 = False
End If

End Sub

Private Sub ToggleButton2_Click()

If bBlockEvent = True Then Exit Sub

If ToggleButton1 = True Then
bBlockEvent = True
ToggleButton1 = False
End If
If ToggleButton3 = True Then
bBlockEvent = True
ToggleButton3 = False
End If
If ToggleButton4 = True Then
bBlockEvent = True
ToggleButton4 = False
End If
If ToggleButton5 = True Then
bBlockEvent = True
ToggleButton5 = False
End If
If ToggleButton6 = True Then
bBlockEvent = True
ToggleButton6 = False
End If

End Sub

Private Sub ToggleButton3_Click()

If bBlockEvent = True Then Exit Sub

If ToggleButton1 = True Then
bBlockEvent = True
ToggleButton1 = False
End If
If ToggleButton2 = True Then
bBlockEvent = True
ToggleButton2 = False
End If
If ToggleButton4 = True Then
bBlockEvent = True
ToggleButton4 = False
End If
If ToggleButton5 = True Then
bBlockEvent = True
ToggleButton5 = False
End If
If ToggleButton6 = True Then
bBlockEvent = True
ToggleButton6 = False
End If

End Sub

Private Sub ToggleButton4_Click()

If bBlockEvent = True Then Exit Sub

If ToggleButton1 = True Then
bBlockEvent = True
ToggleButton1 = False
End If
If ToggleButton2 = True Then
bBlockEvent = True
ToggleButton2 = False
End If
If ToggleButton3 = True Then
bBlockEvent = True
ToggleButton3 = False
End If
If ToggleButton5 = True Then
bBlockEvent = True
ToggleButton5 = False
End If
If ToggleButton6 = True Then
bBlockEvent = True
ToggleButton6 = False
End If

End Sub

Private Sub ToggleButton5_Click()

If bBlockEvent = True Then Exit Sub

If ToggleButton1 = True Then
bBlockEvent = True
ToggleButton1 = False
End If
If ToggleButton2 = True Then
bBlockEvent = True
ToggleButton2 = False
End If
If ToggleButton3 = True Then
bBlockEvent = True
ToggleButton3 = False
End If
If ToggleButton4 = True Then
bBlockEvent = True
ToggleButton4 = False
End If
If ToggleButton6 = True Then
bBlockEvent = True
ToggleButton6 = False
End If

End Sub

Private Sub ToggleButton6_Click()

If bBlockEvent = True Then Exit Sub

If ToggleButton1 = True Then
bBlockEvent = True
ToggleButton1 = False
End If
If ToggleButton2 = True Then
bBlockEvent = True
ToggleButton2 = False
End If
If ToggleButton3 = True Then
bBlockEvent = True
ToggleButton3 = False
End If
If ToggleButton4 = True Then
bBlockEvent = True
ToggleButton4 = False
End If
If ToggleButton5 = True Then
bBlockEvent = True
ToggleButton5 = False
End If
End Sub
 
B

Bob Phillips

Why not use optionbuttons, they work that way by default.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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