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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select option button with code

Status
Not open for further replies.

ronphx

Programmer
Jun 24, 2004
64
US
This is probably extremely simple but I just can't get it. I would like to have my VBA code select an option button in an option group based on the value of a text variable. I don't want the user to have to click the option button, but I would like the user to see that the button has been selected.

Thanks.
 
Something like this:

Sub TextBox1_Change()
Select Case TextBox1.Value
Case "Option1"
OptionButton1.Value = True
Case "Option2"
OptionButton2.Value = True
Case "Option3"
OptionButton3.Value = True
Case Else
OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
End Select
End Sub

So if you type Option1 in the text box, OptionButton1 will be selected, etc.

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
you have to set the frame value to something like so
I have three options in my frame so the third on is checked
Code:
Private Sub Form_Load()
    Me![Frame0].Value = 3
End Sub

also you can use this handy code
the Frame has an After_update event
put this in there
and it will print out which button is picked
Code:
Private Sub Frame0_AfterUpdate()
    MsgBox "you picked " & Frame0.Value '< just add this one line
End Sub

Good Luck

DougP, MCP, A+
 
Thanks to both of you. I did try the optionbutton.value command earlier, but got an error message that said you can't set a value for this object. Apparently the value must be a read only and not a way to set the value for a button.

The frame.value worked perfectly. Thank you so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top