Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am having a problem with this set of code below. What I am trying to do is
to disable all the option buttons in the frame, except for the active option button, when the form initializes. Or, if no option button is selected in the frame, I want all the option buttons to be enabled but if one option button is selected, I want the rest of the option buttons to be disabled. How can I write the code to do that? With Me.fraProject For Each optProject In Me.fraProject If .optProject.Value = True Then .optProject.Enabled = True ElseIf .optProject.Value = False Then .optProject.Enabled = False End If Next End With |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
what error are you getting? or does it simply not work?
you're close: :) For Each optProject In Me.fraProject If optProject.Value = True Then optProject.Enabled = True Else optProject.Enabled = False End If Next optProject you don't have to tell it "if it's false" because there's only 2 options, true or false. so if it's not true, then it's obviously false. and you don't need the With Me.fraProject line because you're already telling it with what in the for-each statement. hope it helps! susan On May 7, 11:37 am, Ayo wrote: I am having a problem with this set of code below. What I am trying to do is to disable all the option buttons in the frame, except for the active option button, when the form initializes. Or, if no option button is selected in the frame, I want all the option buttons to be enabled but if one option button is selected, I want the rest of the option buttons to be disabled. How can I write the code to do that? With Me.fraProject For Each optProject In Me.fraProject If .optProject.Value = True Then .optProject.Enabled = True ElseIf .optProject.Value = False Then .optProject.Enabled = False End If Next End With |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am getting the "Subscript out of range" error. And I can't figure out what
I am doing wrong. "Susan" wrote: what error are you getting? or does it simply not work? you're close: :) For Each optProject In Me.fraProject If optProject.Value = True Then optProject.Enabled = True Else optProject.Enabled = False End If Next optProject you don't have to tell it "if it's false" because there's only 2 options, true or false. so if it's not true, then it's obviously false. and you don't need the With Me.fraProject line because you're already telling it with what in the for-each statement. hope it helps! susan On May 7, 11:37 am, Ayo wrote: I am having a problem with this set of code below. What I am trying to do is to disable all the option buttons in the frame, except for the active option button, when the form initializes. Or, if no option button is selected in the frame, I want all the option buttons to be enabled but if one option button is selected, I want the rest of the option buttons to be disabled. How can I write the code to do that? With Me.fraProject For Each optProject In Me.fraProject If .optProject.Value = True Then .optProject.Enabled = True ElseIf .optProject.Value = False Then .optProject.Enabled = False End If Next End With |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
you might have been getting that because you were referring to
me.fraproject twice. do you still get the same error now? this is in the initialization sub, correct? IS one of the buttons checked? usually in the initialization sub, you set everything to false, so you let the user choose which button to select. since you are doing this in the initilization sub, how are you setting one of them to true? susan On May 7, 12:00 pm, Ayo wrote: I am getting the "Subscript out of range" error. And I can't figure out what I am doing wrong. "Susan" wrote: what error are you getting? or does it simply not work? you're close: :) For Each optProject In Me.fraProject If optProject.Value = True Then optProject.Enabled = True Else optProject.Enabled = False End If Next optProject you don't have to tell it "if it's false" because there's only 2 options, true or false. so if it's not true, then it's obviously false. and you don't need the With Me.fraProject line because you're already telling it with what in the for-each statement. hope it helps! susan On May 7, 11:37 am, Ayo wrote: I am having a problem with this set of code below. What I am trying to do is to disable all the option buttons in the frame, except for the active option button, when the form initializes. Or, if no option button is selected in the frame, I want all the option buttons to be enabled but if one option button is selected, I want the rest of the option buttons to be disabled. How can I write the code to do that? With Me.fraProject For Each optProject In Me.fraProject If .optProject.Value = True Then .optProject.Enabled = True ElseIf .optProject.Value = False Then .optProject.Enabled = False End If Next End With- Hide quoted text - - Show quoted text - |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
also, i don't see anything "dimmed".
you'd need Dim optProject as Control and i missed this For Each optProject In fraProject.Controls you don't need to refer to "me" because you're already in the userform initialization sub. :) susan On May 7, 12:00 pm, Ayo wrote: I am getting the "Subscript out of range" error. And I can't figure out what I am doing wrong. "Susan" wrote: what error are you getting? or does it simply not work? you're close: :) For Each optProject In Me.fraProject If optProject.Value = True Then optProject.Enabled = True Else optProject.Enabled = False End If Next optProject you don't have to tell it "if it's false" because there's only 2 options, true or false. so if it's not true, then it's obviously false. and you don't need the With Me.fraProject line because you're already telling it with what in the for-each statement. hope it helps! susan On May 7, 11:37 am, Ayo wrote: I am having a problem with this set of code below. What I am trying to do is to disable all the option buttons in the frame, except for the active option button, when the form initializes. Or, if no option button is selected in the frame, I want all the option buttons to be enabled but if one option button is selected, I want the rest of the option buttons to be disabled. How can I write the code to do that? With Me.fraProject For Each optProject In Me.fraProject If .optProject.Value = True Then .optProject.Enabled = True ElseIf .optProject.Value = False Then .optProject.Enabled = False End If Next End With- Hide quoted text - - Show quoted text - |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ok, i think this is what you want.
Private Sub optionbutton1_click() Call Disable_Controls End Sub Private Sub optionbutton2_click() Call Disable_Controls End Sub Private Sub optionbutton3_click() Call Disable_Controls End Sub 'add as many as you need for all your control buttons Sub Disable_Controls Dim optProject As Control For Each optProject In fraProject.Controls If optProject.Value = True Then optProject.Enabled = True Else optProject.Enabled = False End If Next optProject End Sub no matter which option button is selected, the other ones will become disabled. this does NOT go in the initialization sub. they are separate subs within the userform coding. hope this (finally!) helps :) susan |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks a lot Susan for all the help. Everything is working great now.
"Susan" wrote: ok, i think this is what you want. Private Sub optionbutton1_click() Call Disable_Controls End Sub Private Sub optionbutton2_click() Call Disable_Controls End Sub Private Sub optionbutton3_click() Call Disable_Controls End Sub 'add as many as you need for all your control buttons Sub Disable_Controls Dim optProject As Control For Each optProject In fraProject.Controls If optProject.Value = True Then optProject.Enabled = True Else optProject.Enabled = False End If Next optProject End Sub no matter which option button is selected, the other ones will become disabled. this does NOT go in the initialization sub. they are separate subs within the userform coding. hope this (finally!) helps :) susan |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Option Buttons/Radio Buttons | New Users to Excel | |||
Looping through buttons on a worksheet. | Excel Programming | |||
Option buttons: How to get the selected option from a group? | Excel Programming | |||
Navigating between option buttons is not selecting the option | Excel Programming | |||
Navigating between option buttons is not selecting the option | Excel Programming |