PC Review


Reply
Thread Tools Rate Thread

Conditionally Disabling Optionbuttons

 
 
kgriba
Guest
Posts: n/a
 
      5th Feb 2008
I have two option buttons (from the Control Toolbox in Excel 2003) named
"OptionButton18" and "OptionButton19", both of which have the GroupName
"nameWallTile."

OptionButton18 also has what I am considering a subgroup of 3 option
buttons, all of which have the GroupName "nameWallTileBKSP"

I would like the group "nameWallTileBKSP" of OptionButton18 to be disabled
when OptionButton19 is selected.

Any suggestions? I'm not very familiar with VB, but am not afraid of
learning something new, especially about Excel!

Thanks!
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      5th Feb 2008
You could just use the names of the 3 "sub-optionbuttons" and disable them. But
if you add more optionbuttons to that group "nameWallTileBKSP", then you'll have
to update the code for those names.

Another way is to loop through all the OLEobjects on the sheet and look at the
groupname and decide to enable/disable it based on the "checkedness" of
optionbutton19.

This goes under the worksheet module that owns those optionbuttons:

Option Explicit
Private Sub OptionButton18_Click()
Call CheckSubGroup
End Sub
Private Sub OptionButton19_Click()
Call CheckSubGroup
End Sub
Sub CheckSubGroup()

Dim OLEObj As OLEObject
Dim myEnabled As Boolean

myEnabled = Not (Me.OptionButton19.Value)

For Each OLEObj In Me.OLEObjects
If TypeOf OLEObj.Object Is MSForms.OptionButton Then
If LCase(OLEObj.Object.GroupName) = LCase("nameWallTileBKSP") Then
OLEObj.Enabled = myEnabled
'OLEObj.Object.Value = False
End If
End If
Next OLEObj

End Sub

kgriba wrote:
>
> I have two option buttons (from the Control Toolbox in Excel 2003) named
> "OptionButton18" and "OptionButton19", both of which have the GroupName
> "nameWallTile."
>
> OptionButton18 also has what I am considering a subgroup of 3 option
> buttons, all of which have the GroupName "nameWallTileBKSP"
>
> I would like the group "nameWallTileBKSP" of OptionButton18 to be disabled
> when OptionButton19 is selected.
>
> Any suggestions? I'm not very familiar with VB, but am not afraid of
> learning something new, especially about Excel!
>
> Thanks!


--

Dave Peterson
 
Reply With Quote
 
kgriba
Guest
Posts: n/a
 
      5th Feb 2008
Hi Dave... thanks... gave that a try and probably due to my lack of
understanding, got an error message popup, "Invalid Use of the Me Keyword."
I've learned in the editor that it's likely having to do with my incorrect
placement of your code into "Module1".

I wasn't really sure what "This goes under the worksheet module that owns
those optionbuttons:" meant, so I guessed. I copy-pasted your code into the
only module I can see in the editor, that would be "Module1".

Do I need to create a module with a name associated with the GroupNames or
OptionButton names?

Thanks again,
Kristine



"Dave Peterson" wrote:

> You could just use the names of the 3 "sub-optionbuttons" and disable them. But
> if you add more optionbuttons to that group "nameWallTileBKSP", then you'll have
> to update the code for those names.
>
> Another way is to loop through all the OLEobjects on the sheet and look at the
> groupname and decide to enable/disable it based on the "checkedness" of
> optionbutton19.
>
> This goes under the worksheet module that owns those optionbuttons:
>
> Option Explicit
> Private Sub OptionButton18_Click()
> Call CheckSubGroup
> End Sub
> Private Sub OptionButton19_Click()
> Call CheckSubGroup
> End Sub
> Sub CheckSubGroup()
>
> Dim OLEObj As OLEObject
> Dim myEnabled As Boolean
>
> myEnabled = Not (Me.OptionButton19.Value)
>
> For Each OLEObj In Me.OLEObjects
> If TypeOf OLEObj.Object Is MSForms.OptionButton Then
> If LCase(OLEObj.Object.GroupName) = LCase("nameWallTileBKSP") Then
> OLEObj.Enabled = myEnabled
> 'OLEObj.Object.Value = False
> End If
> End If
> Next OLEObj
>
> End Sub
>
> kgriba wrote:
> >
> > I have two option buttons (from the Control Toolbox in Excel 2003) named
> > "OptionButton18" and "OptionButton19", both of which have the GroupName
> > "nameWallTile."
> >
> > OptionButton18 also has what I am considering a subgroup of 3 option
> > buttons, all of which have the GroupName "nameWallTileBKSP"
> >
> > I would like the group "nameWallTileBKSP" of OptionButton18 to be disabled
> > when OptionButton19 is selected.
> >
> > Any suggestions? I'm not very familiar with VB, but am not afraid of
> > learning something new, especially about Excel!
> >
> > Thanks!

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Feb 2008
Select the worksheet with the optionbuttons.

Rightclick on the worksheet tab and select View Code.

Paste the code here.

And clean up that code you put in a general module. It doesn't belong there.



kgriba wrote:
>
> Hi Dave... thanks... gave that a try and probably due to my lack of
> understanding, got an error message popup, "Invalid Use of the Me Keyword."
> I've learned in the editor that it's likely having to do with my incorrect
> placement of your code into "Module1".
>
> I wasn't really sure what "This goes under the worksheet module that owns
> those optionbuttons:" meant, so I guessed. I copy-pasted your code into the
> only module I can see in the editor, that would be "Module1".
>
> Do I need to create a module with a name associated with the GroupNames or
> OptionButton names?
>
> Thanks again,
> Kristine
>
> "Dave Peterson" wrote:
>
> > You could just use the names of the 3 "sub-optionbuttons" and disable them. But
> > if you add more optionbuttons to that group "nameWallTileBKSP", then you'll have
> > to update the code for those names.
> >
> > Another way is to loop through all the OLEobjects on the sheet and look at the
> > groupname and decide to enable/disable it based on the "checkedness" of
> > optionbutton19.
> >
> > This goes under the worksheet module that owns those optionbuttons:
> >
> > Option Explicit
> > Private Sub OptionButton18_Click()
> > Call CheckSubGroup
> > End Sub
> > Private Sub OptionButton19_Click()
> > Call CheckSubGroup
> > End Sub
> > Sub CheckSubGroup()
> >
> > Dim OLEObj As OLEObject
> > Dim myEnabled As Boolean
> >
> > myEnabled = Not (Me.OptionButton19.Value)
> >
> > For Each OLEObj In Me.OLEObjects
> > If TypeOf OLEObj.Object Is MSForms.OptionButton Then
> > If LCase(OLEObj.Object.GroupName) = LCase("nameWallTileBKSP") Then
> > OLEObj.Enabled = myEnabled
> > 'OLEObj.Object.Value = False
> > End If
> > End If
> > Next OLEObj
> >
> > End Sub
> >
> > kgriba wrote:
> > >
> > > I have two option buttons (from the Control Toolbox in Excel 2003) named
> > > "OptionButton18" and "OptionButton19", both of which have the GroupName
> > > "nameWallTile."
> > >
> > > OptionButton18 also has what I am considering a subgroup of 3 option
> > > buttons, all of which have the GroupName "nameWallTileBKSP"
> > >
> > > I would like the group "nameWallTileBKSP" of OptionButton18 to be disabled
> > > when OptionButton19 is selected.
> > >
> > > Any suggestions? I'm not very familiar with VB, but am not afraid of
> > > learning something new, especially about Excel!
> > >
> > > Thanks!

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
kgriba
Guest
Posts: n/a
 
      5th Feb 2008
Brilliant! Worked like a charm! There's no way I would have figured that one
out on my own. And, I've cleaned up the general module as well (actually did
that after the error message pop-up.)

Thanks again,
Kristine

"Dave Peterson" wrote:

> Select the worksheet with the optionbuttons.
>
> Rightclick on the worksheet tab and select View Code.
>
> Paste the code here.
>
> And clean up that code you put in a general module. It doesn't belong there.
>
>
>
> kgriba wrote:
> >
> > Hi Dave... thanks... gave that a try and probably due to my lack of
> > understanding, got an error message popup, "Invalid Use of the Me Keyword."
> > I've learned in the editor that it's likely having to do with my incorrect
> > placement of your code into "Module1".
> >
> > I wasn't really sure what "This goes under the worksheet module that owns
> > those optionbuttons:" meant, so I guessed. I copy-pasted your code into the
> > only module I can see in the editor, that would be "Module1".
> >
> > Do I need to create a module with a name associated with the GroupNames or
> > OptionButton names?
> >
> > Thanks again,
> > Kristine
> >
> > "Dave Peterson" wrote:
> >
> > > You could just use the names of the 3 "sub-optionbuttons" and disable them. But
> > > if you add more optionbuttons to that group "nameWallTileBKSP", then you'll have
> > > to update the code for those names.
> > >
> > > Another way is to loop through all the OLEobjects on the sheet and look at the
> > > groupname and decide to enable/disable it based on the "checkedness" of
> > > optionbutton19.
> > >
> > > This goes under the worksheet module that owns those optionbuttons:
> > >
> > > Option Explicit
> > > Private Sub OptionButton18_Click()
> > > Call CheckSubGroup
> > > End Sub
> > > Private Sub OptionButton19_Click()
> > > Call CheckSubGroup
> > > End Sub
> > > Sub CheckSubGroup()
> > >
> > > Dim OLEObj As OLEObject
> > > Dim myEnabled As Boolean
> > >
> > > myEnabled = Not (Me.OptionButton19.Value)
> > >
> > > For Each OLEObj In Me.OLEObjects
> > > If TypeOf OLEObj.Object Is MSForms.OptionButton Then
> > > If LCase(OLEObj.Object.GroupName) = LCase("nameWallTileBKSP") Then
> > > OLEObj.Enabled = myEnabled
> > > 'OLEObj.Object.Value = False
> > > End If
> > > End If
> > > Next OLEObj
> > >
> > > End Sub
> > >
> > > kgriba wrote:
> > > >
> > > > I have two option buttons (from the Control Toolbox in Excel 2003) named
> > > > "OptionButton18" and "OptionButton19", both of which have the GroupName
> > > > "nameWallTile."
> > > >
> > > > OptionButton18 also has what I am considering a subgroup of 3 option
> > > > buttons, all of which have the GroupName "nameWallTileBKSP"
> > > >
> > > > I would like the group "nameWallTileBKSP" of OptionButton18 to be disabled
> > > > when OptionButton19 is selected.
> > > >
> > > > Any suggestions? I'm not very familiar with VB, but am not afraid of
> > > > learning something new, especially about Excel!
> > > >
> > > > Thanks!
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling/Disabling OptionButtons, CheckBoxes etc. in another works Will Microsoft Excel Programming 1 11th Jan 2009 02:07 PM
disabling control tip text conditionally =?Utf-8?B?VGVk?= Microsoft Access Form Coding 4 21st Feb 2006 06:41 PM
Conditionally disabling formulas nebb Microsoft Excel Programming 0 26th Oct 2004 04:25 PM
Conditionally disabling controls on subform =?Utf-8?B?Qm9iIE11bGxlbg==?= Microsoft Access Form Coding 3 8th Jun 2004 12:09 PM
Disabling a 'Group' of OptionButtons JimP Microsoft Excel Programming 2 26th Jan 2004 02:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:02 PM.