Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Grouped option buttons on forms

This should be easy...how does one determine which of a set of grouped
option buttons is selected? Let's say I have 4 option buttons
(optionbutton1, optionbutton2, etc) with groupname set to Season. The
user selects....winter, which corresponds to optionbutton4. I can
check each one...

If Userform1.OptionButton1.Value = -1 Then x = 1
If Userform1.OptionButton2.Value = -1 Then x = 2
If Userform1.OptionButton3.Value = -1 Then x = 3
If Userform1.OptionButton4.Value = -1 Then x = 4

but there MUST be a better way!! I have many groups and many, many
option buttons on my form. The above solution quickly becomes
tedious.

Thanks,
John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Grouped option buttons on forms

Dim c As Control
Dim x As Integer
For Each c In UserForm1.Controls
If c.GroupName = "Season" And c.Value = True Then
x = Right(c.Name, Len(c.Name) - 12)
End If
Next c

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Grouped option buttons on forms

for i = 1 to 4
set ctrl = me.controls("OptionButton" & i)
if ctrl.Value then
x = i
exit for
end if
next

There is no me.Groups(groupname).Value that will tell you the name of the
optionbutton or anything like that.

--
regards,
Tom Ogilvy


" wrote:

This should be easy...how does one determine which of a set of grouped
option buttons is selected? Let's say I have 4 option buttons
(optionbutton1, optionbutton2, etc) with groupname set to Season. The
user selects....winter, which corresponds to optionbutton4. I can
check each one...

If Userform1.OptionButton1.Value = -1 Then x = 1
If Userform1.OptionButton2.Value = -1 Then x = 2
If Userform1.OptionButton3.Value = -1 Then x = 3
If Userform1.OptionButton4.Value = -1 Then x = 4

but there MUST be a better way!! I have many groups and many, many
option buttons on my form. The above solution quickly becomes
tedious.

Thanks,
John


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Grouped option buttons on forms

Got it.....thanks guys.

JH


On Feb 12, 2:59 pm, Tom Ogilvy
wrote:
for i = 1 to 4
set ctrl = me.controls("OptionButton" & i)
if ctrl.Value then
x = i
exit for
end if
next

There is no me.Groups(groupname).Value that will tell you the name of the
optionbutton or anything like that.

--
regards,
Tom Ogilvy


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Grouped option buttons on forms

On Feb 12, 2:58 pm, "merjet" wrote:
Dim c As Control
Dim x As Integer
For Each c In UserForm1.Controls
If c.GroupName = "Season" And c.Value = True Then
x = Right(c.Name, Len(c.Name) - 12)
End If
Next c

Hth,
Merjet




I spoke too soon....I want to check each by GroupName and Value, but
c.GroupName is not valid. Only OptionButtons have GroupNames,
controls do not. So I tried:

Dim o As OptionButton

DrngPied.Show 'DrngPied is the form

For Each o In DrngPied.Controls
If o.GroupName = "SizeOptions" And o.Value = -1 Then
sSize = c.Name
End If
Next o


but I get a Type Mismatch at the For Each line.

John



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Grouped option buttons on forms

Dim c As Control
Dim x As Integer
For Each c In UserForm1.Controls

if typeof c is MSForms.OptionButton then
If c.GroupName = "Season" And c.Value = True Then
x = Right(c.Name, Len(c.Name) - 12)
End If

End If
Next c


--
Regards,
Tom Ogilvy

wrote in message
ups.com...
On Feb 12, 2:58 pm, "merjet" wrote:
Dim c As Control
Dim x As Integer
For Each c In UserForm1.Controls
If c.GroupName = "Season" And c.Value = True Then
x = Right(c.Name, Len(c.Name) - 12)
End If
Next c

Hth,
Merjet




I spoke too soon....I want to check each by GroupName and Value, but
c.GroupName is not valid. Only OptionButtons have GroupNames,
controls do not. So I tried:

Dim o As OptionButton

DrngPied.Show 'DrngPied is the form

For Each o In DrngPied.Controls
If o.GroupName = "SizeOptions" And o.Value = -1 Then
sSize = c.Name
End If
Next o


but I get a Type Mismatch at the For Each line.

John



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, Forms Control, Excel 2007 - 3 options Paula Excel Worksheet Functions 6 February 6th 09 07:36 PM
Option Buttons from the Forms Toolbar - Excel 2003 mickey Excel Worksheet Functions 2 October 14th 07 11:32 AM
Forms Option Buttons(Can be right mouse selected when sheet is loc Newbeetle Excel Discussion (Misc queries) 2 February 10th 07 04:12 PM
Option Buttons on User Forms ibeetb Excel Programming 1 October 30th 03 10:06 PM
Forms: Group Boxes and Option Buttons Kathryn[_4_] Excel Programming 2 October 17th 03 02:11 AM


All times are GMT +1. The time now is 10:35 PM.

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

About Us

"It's about Microsoft Excel"