OptionButton Group question

P

Patrick C. Simonds

On my UserForm I have a number of OptionButton groups and each group has a
Label associated to it. This is a series of questions with 3 possible
answers for each question.

What I would like is some code which would change the color of the text in
the label from black to red, if none of the 3 OptionButtons in the group is
true. I am hoping this could be done by Option Group as opposed to writing a
click event for each OptionButton.
 
D

Doug Robbins - Word MVP

It would have to be done by some external click event such as by a command
button because once you click on one option button, you can only "unclick"
it by clicking on another option button so that after one has been clicked,
one of them will always be true.

The following run under some other event, a command button click for example
will however achieve what you want

If OptionButton1.Value = False Then
If OptionButton2.Value = False Then
If OptionButton3.Value = Flase Then
Frame1.ForeColor = wdColorRed
Else
Frame1.ForeColor = wdColorAuto
End If
Else
Frame1.ForeColor = wdColorAuto
End If
Else
Frame1.ForeColor = wdColorAuto
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Patrick C. Simonds

Well I think I will (at least initially) do it as part of the UserForm
Initialization, so is there any way to reference the GroupName? In this case
the GroupNames will be Question1, Question2 and so on.
 
P

Perry

Dim lTest As Long
lTest = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3)
Me.Frame1.BackColor = IIf(lTest, Me.BackColor, vbRed)


--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
D

Doug Robbins - Word MVP

I don't believe that you need do anything with the group name, it is either
the captions of the frames in which each group of option buttons would be
inserted, or some other label on your form whose attribute you want to set.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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