Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Looping through Option buttons

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Looping through Option buttons

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   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Looping through Option buttons

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Looping through Option buttons

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Looping through Option buttons

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Looping through Option buttons

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   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Looping through Option buttons

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option Buttons/Radio Buttons John Calder New Users to Excel 7 May 16th 08 03:51 AM
Looping through buttons on a worksheet. Libby Excel Programming 3 February 23rd 07 09:36 AM
Option buttons: How to get the selected option from a group? naddad Excel Programming 5 December 21st 05 05:09 PM
Navigating between option buttons is not selecting the option drhalter Excel Programming 1 June 3rd 05 02:28 PM
Navigating between option buttons is not selecting the option Gixxer_J_97[_2_] Excel Programming 4 June 2nd 05 02:50 PM


All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"