How to referance a GroupName

G

Garry

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
 
T

Tom Ogilvy

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.
 
G

Garry

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
 
T

Tom Ogilvy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top