Colour OptionButtons on initialize and change

S

snafu

I have a form which is designed to examine data line by line, and
reformats the data after a user double checks it for correctness. I
want to make it a bit easier for the user to quickly see which options
are selected. Is there a universal way to have any change in the form
which relates to OptionButtons state being either 'true' or 'false' to
trigger a change to .Background for that OptionButton.

I've started with a series of _Click() commands and _Initialize(),
however I'd like to avoid having to name each function individually.

Thanks.
 
P

Perry

are selected. Is there a universal way to have any change in the form
which relates to OptionButtons state being either 'true' or 'false' to

Yes, various.
But it's no use showing you more complicated solutions, if you can't a grasp
of below example.

Below UserForm code sequence applies to a userform consisting of 3
OptionButtons only.
It will change the backcolor, using one subroutine.
In a "real life" scenario, you would have to deal with a lot more controls
on yr userform, so you will have to deal with that.

== begin usreform code
Private Sub OptionButton1_Click()
ClickMe Me.OptionButton1
End Sub

Private Sub OptionButton2_Click()
ClickMe Me.OptionButton2
End Sub

Private Sub OptionButton3_Click()
ClickMe Me.OptionButton3
End Sub

Private Sub UserForm_Initialize()
ClickMe Me.OptionButton1
End Sub

Private Sub ClickMe(ByVal OB As MSForms.OptionButton)
'reset the backcolors to vbYellow
For Each txt In Me.Controls
txt.BackColor = vbYellow
Next
'apply the vbRed backcolor, if true
If OB Then OB.BackColor = vbRed
End Sub
=== end userform code

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
S

snafu

Thanks for your help. Unfortunately, I'll need to find some other way
since the solution provided colors everything, and seems to overwrite
the existing colour formates. Is there a way to refine this by frame
instead of the whole document?

I have colour coded text boxes which need to retain their formating,
ditto for my toggle buttons. I already have my toggle buttons colour
coded. The only thing I need to have change is the .backcolor on my
optionbuttons.

Once again, thank you for taking the time to respond.
 
P

Perry

Not clear what y're trying to achieve here ...

1) are we speaking about UserForms (dialogscreens) or Online Forms (Form
protected documents)?
2) clearly indicate (if first question is made clear) which actions need to
result in which format. It's not clear at the moment.
Y're initial post doesn't match yr last post ...

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
S

snafu

My apologies for any confusion.

This is a userform, no internet is invovled with this.

The form has 8 frames, 6 of the frames have 2 to 5 option buttons, 2
of the frames use togglebuttons, there are about a dozen textboxes,
and 4 command buttons.

The command buttons have to be colour coded, the text boxes should be
coloured, and it would be nice to have colour associated with the
option buttons.

Below is an example for one of the frames followed by an example of
the startup code I'm using.

I'm just looking for a slicker way to get the option buttons to change
their backcolor value and font size.

So that whenever an option button gets clicked and also at startup the
various option buttons evaluate if they are set to true or false.
if false do one action, if true do an different one. I don't want the
togglebuttons to do this, nor any other modification to the rest of
the form.

Also, is there a way to have a button's backcolor automatically pickup
the form backcolor?

Thanks again.

Private Sub IFR_Click()
Me.IFR.BackColor = &HC000& 'GREEN
Me.IFR.Font.Size = 12
Me.VFR.BackColor = &HFFFFC0 'Lt Blue
Me.VFR.Font.Size = 10
End Sub

Private Sub VFR_Click()
Me.VFR.BackColor = &HC000& 'GREEN
Me.VFR.Font.Size = 12
Me.IFR.BackColor = &HFFFFC0 'Lt Blue
Me.IFR.Font.Size = 10
End Sub

Sub ExerciseBuilderInterface()
ExerciseBuilderForm.Show
ExerciseBuilderForm.IFR.BackColor = &HC000& 'GREEN
ExerciseBuilderForm.IFR.Font.Size = 12
End Sub
 

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