ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to referance a GroupName (https://www.excelbanter.com/excel-programming/312389-how-referance-groupname.html)

Garry[_7_]

How to referance a GroupName
 

I have a frame containing three optionbuttons. I have set the groupname
in the properties inspector manaually to "TaxGroup".

How do i reference this ie get the value or a value of it. Could I use
the select case statement to then action on which optionbutton is true.

Select Case Controls("TaxGroup").Value

Case Is = 1

Case "OptionButton1": txtTax.Value = "Includes"
Case "OptionButton2": txtTax.Value = "Excludes"
Case "OptionButton3": txtTax.Value = "Non Taxable"
End Select

garry

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

How to referance a GroupName
 
There is not a "group" object as you seem to want to use.

Dim obtn as MSforms.OptionButton
Dim cntrl as Control
set obtn = nothing
for each cntrl in Userform1.Frame1.Controls
if typeof cntrl is MSforms.OptionButton then
if cntrl.groupname = "TaxGroup" then
if cntrl then
set obtn = cntrl
exit for
end if
end if
end if
Next
if not obtn is nothing then
Select Case obtn.Name
Case "OptionButton1": txtTax.Value = "Includes"
Case "OptionButton2": txtTax.Value = "Excludes"
Case "OptionButton3": txtTax.Value = "Non Taxable"
End Select

Else
msgbox "None Selected"
End if

you can take out the check for TaxGroup if those are the only option buttons
in the frame.
--
Regards,
Tom Ogilvy


"Garry" wrote in message
...

I have a frame containing three optionbuttons. I have set the groupname
in the properties inspector manaually to "TaxGroup".

How do i reference this ie get the value or a value of it. Could I use
the select case statement to then action on which optionbutton is true.

Select Case Controls("TaxGroup").Value

Case Is = 1

Case "OptionButton1": txtTax.Value = "Includes"
Case "OptionButton2": txtTax.Value = "Excludes"
Case "OptionButton3": txtTax.Value = "Non Taxable"
End Select

garry

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Garry[_7_]

How to referance a GroupName
 
Tom

Tx.

I had to change the last bit to get it to work, thats my fault.

If Not obtn Is Nothing Then
Select Case obtn.Name
Case "OptionButton1"
txtTax = "Includes"
Case "OptionButton2"
txtTax = "Excludes"
Case "OptionButton3"
txtTax = "Non Taxable"

End Select

I have two frames on the form and was wondering if I could combine them
in one loop statement. At the moment I have just duplicated the original
code and changed the variables.

Group name is "TypeGroup"
If Not obtn Is Nothing Then
Select Case obtn.Name
Case "OptionButton4"
txtType = "Fees"
Case "OptionButton5"
txtType = "Expenses"

End Select

garrygdc

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

How to referance a GroupName
 
Public Function GetButton(fr as MSForms.Frame, grpName as String)
Dim obtn as MSforms.OptionButton
Dim cntrl as Control
set obtn = nothing
for each cntrl in fr
if typeof cntrl is MSforms.OptionButton then
if lcase(cntrl.groupname) = lCase(grpName) then
if cntrl then
set obtn = cntrl
exit for
end if
end if
end if
Next
set GetButton = obtn
End Function

Private Sub CommandButton1_Click
Dim oBtn1 as MSForms.OptionButton
Dim oBtn2 as MSForms.OptionButton
set oBtn1 = GetButton(Userform1.Frame1, "TaxGroup")
set oBtn2 = GetButton(Userform1.Frame2, "TypeGroup")
If Not obtn1 Is Nothing Then
Select Case obtn1.Name
Case "OptionButton1"
txtTax = "Includes"
Case "OptionButton2"
txtTax = "Excludes"
Case "OptionButton3"
txtTax = "Non Taxable"
End Select
End if

If Not obtn2 Is Nothing Then
Select Case obtn2.Name
Case "OptionButton4"
txtType = "Fees"
Case "OptionButton5"
txtType = "Expenses"
End Select
End if

End Sub

Might be one approach.

--
Regards,
Tom Ogilvy


"Garry" wrote in message
...
Tom

Tx.

I had to change the last bit to get it to work, thats my fault.

If Not obtn Is Nothing Then
Select Case obtn.Name
Case "OptionButton1"
txtTax = "Includes"
Case "OptionButton2"
txtTax = "Excludes"
Case "OptionButton3"
txtTax = "Non Taxable"

End Select

I have two frames on the form and was wondering if I could combine them
in one loop statement. At the moment I have just duplicated the original
code and changed the variables.

Group name is "TypeGroup"
If Not obtn Is Nothing Then
Select Case obtn.Name
Case "OptionButton4"
txtType = "Fees"
Case "OptionButton5"
txtType = "Expenses"

End Select

garrygdc

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





All times are GMT +1. The time now is 02:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com