Many Toggle Buttons

R

Rachel

I have over two hundred toggle buttons on a form. Is there a way to write
"general" code rather than code each button that will turn the font red on the
button I turn on and turn the font back on the button I turn off?

I'm trying to save not having to code each button but have individual buttons
react to On and Off.

Thanks!

Rachel
 
A

Andrew Smith

This function will do the job:

Private Function ToggleColour(ID As Long)
Me("Toggle" & ID).ForeColor = -255 * Me("Toggle" & ID)
End Function

It assumes your toggle buttons are named "Toggle" then a number - eg
Toggle1, toggle2 etc. In the after update property for each toggle button
put "=ToggleColour(1)" (change the 1 for the number at the end of the
control name). You could write some code to do this for you.
 
M

Marshall Barton

Rachel said:
I have over two hundred toggle buttons on a form. Is there a way to write
"general" code rather than code each button that will turn the font red on the
button I turn on and turn the font back on the button I turn off?

I'm trying to save not having to code each button but have individual buttons
react to On and Off.

Create a public function:

Public Function ToggleClick()
IF Me.ActiveControl = True Then
Me.ActiveControl.Forecolor = vbRed
Else
Me.ActiveControl.Forecolor = vbBlack
End If
End Function

Then drag a selection box over all the toggle buttons and
set the OnClick property of all of them to:

=ToggleClick()
 

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