Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Self-renaming Option Buttons

Status
Not open for further replies.

SaintAugustine

Technical User
Aug 29, 2001
53
US
I'm trying to make an option button rename itself when it's selected. So my question is, is there an object name for a Control? "ActiveButton" or something?

Basically, what I'm trying to do is have option buttons that say:
Do you own a dog?
* Yes * No

If the user selects Yes, an input box will pop up and say "How Many Dogs?" Then it will rename the Yes button to "Yes - 3 Dogs"

Here's what I've got:

Sub RenameSelectedButton()

Dim myNumberDogs As Integer
myNumberDogs = InputBox("How many dogs do you have?")

If myNumberDogs = "" Then End

ActiveSheet.Shapes.Select ' ???????

Selection.Characters.Text = "Yes - " & myNumberDogs & " dogs"

It would be nice if the reference was relative - ie, there's many, many option buttons like these, and I'd rather not have to go through and identify them by hand.

Thanks!


End Sub
 

Hi. Is this what you're trying to do...? I'm not sure if all you want to do is merely change the caption after the users input . I have slightly tweaked your code for this with the addition of the IsNumeric line to firstly check the input is numeric.


Sub RenameSelectedButton()

Dim MyNumberDogs

MmyNumberDogs = InputBox("How many dogs do you have?")

If (Not (IsNumeric(MyNumberDogs))) Then MsgBox "Try again & enter a number": Exit Sub
If MyNumberDogs = "0" Then Exit Sub
If MyNumberDogs = "" Then Exit Sub

If MyNumberDogs > 0 Then
ActiveSheet.OptionButton1.Caption = "Yes - " & MyNumberDogs & " dogs"

End If
End Sub


Hope this helps.


mudstuffin
 
Hi SaintAugustine,

I did some "testing" and came up with an alternative you might want to have a look at.

If you like, I can email you the file. :)

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top