Re: Switching optionbuttons – how to make it a correct
thanks you for reply.
Note, that I can't make so. Because those OptionButtons each time are there other (have a look on their name) the array of controls would be the best solution, but there is no something like this in a VBA.
Re: Switching optionbuttons – how to make it a correct
Thanks, sorry but.....you didn't understand me probably. I attached file and you have a look. Your solution can't work correctly because always it a refer to a different of group of objects.
So therefore please you again, you have a look on the names of objects - always are other
Re: Switching optionbuttons – how to make it a correct
Ok, I didn't realize this was Excel. I don't know as much about Excel, so take this for what it's worth.
You may need to put Me. in front of your statements:
VB Code:
Me.optTrap.BackColor = &HC0FFFF
For some things you may need to SetFocus before setting properties:
VB Code:
optTrap.SetFocus
optTrap.BackColor = &HC0FFFF
I'm not sure when you need to do one or the other. I think it depends on what property you're setting.
Anyway, I can't test it on the file you sent because security settings won't let me change the code.
Re: Switching optionbuttons – how to make it a correct
Hi All
Okay, I found here any code and I modified it
An works it fine for me, but I have other problem now.
I have a three of sections (frame) with the optionbutton controls. If I use this code
then this code to make that only one option will be active and all other will be not active. It will be not correctly.
My question is:
how to make that those all of section would be it works completely of irrespective
here's this code, it work with the objects (optionbutton) only in a one Frame.
VB Code:
Private Sub Highlight_Control(Optional MarkControl As Control)
Dim cMyControl As Control
For Each cMyControl In Me.Controls
If Left(cMyControl.Name, 3) = "Opt" Then
With cMyControl
.BackColor = 10931133
.ForeColor = &H4080&
End With
End If
Next cMyControl
If Not MarkControl Is Nothing Then
With MarkControl
.BackColor = &HC0FFFF
.ForeColor = &HFF0000
End With
End If
End Sub
'>>> for a optionbutton:
Private Sub optTrap_Click()
Highlight_Control optTrap
End Sub
'>>>. . . . . . etc, etc for each the optionbuttons in a this section
thanks in advance
Last edited by Tamgovb; Jun 20th, 2006 at 05:11 AM.
Re: Switching optionbuttons – how to make it a correct
Tamgovb
You will need to change this lie
VB Code:
For Each cMyControl In Me.Controls
to
VB Code:
For Each cMyControl In Me.Frame1.Controls
or whatever the name of the frame is. This change means that the code now only loops throught the controls in frame1 and not all the controls on the form
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful
Re: Switching optionbuttons – how to make it a correct
Try the following version of the Highlight_Control procedure. When calling it, you will need to include both the OptionButton and the Frame as parameters.
e.g.
VB Code:
Private Sub OptionButton1_Click()
Highlight_Control Me.OptionButton1, Me.Frame1
End Sub
Here's the revised procedure.
VB Code:
Private Sub Highlight_Control(ByRef MarkControl As Control, ByRef OptFrame As Control)
Dim cMyControl As Control
If TypeName(OptFrame) <> "Frame" _
Or TypeName(MarkControl) <> "OptionButton" Then
Exit Sub
End If
For Each cMyControl In OptFrame.Controls
If TypeName(cMyControl) = "OptionButton" Then
With cMyControl
.BackColor = 10931133
.ForeColor = &H4080&
End With
End If
Next cMyControl
With MarkControl
.BackColor = &HC0FFFF
.ForeColor = &HFF0000
End With
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful