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

option buttons

Status
Not open for further replies.

bencnu

Technical User
Nov 3, 2003
34
US
Is there a way to select an option button when hit a regular button? by using Optionbutton2.activate it will select the option button but it won't avtivate it or put the little dot in it
 
Hi,

Use the CommandButton click event to assign the value to the OptionButton.

Here's an example of what you can do...
Code:
Private Sub CommandButton1_Click()
    If OptionButton1 Then
        OptionButton2.Value = OptionButton1.Value
    Else
        OptionButton1.Value = OptionButton2.Value
    End If
End Sub


Skip,
Skip@TheOfficeExperts.com
 
bencnu:

<whispered reminder>
Pssst - I think the Skipper deserves a star for a helpful answer!
</whispered reminder>

VBAjedi [swords]
 
bencnu, why would you want to do that? Users have certain expectations on how buttons and option buttons (and check boxes, ect.) work. Causing an option button to change when clicking a command button would be unxpected. Are you purposely trying to annoy your users?

To pre-set the first option button, set its &quot;Value&quot; property to true. All option buttons with the same &quot;Group Name&quot; property will behave the way option buttons should. (I.e., click one on and all the others go off.) If you have multiple groups of option buttons (e.g. like Excel's Tools/Options.../View) just give them different group names.

This assumes the option buttons are on a user form. You didn't specify, so I should ask: Where are the option buttons placed? If directly on a sheet, which tool bar did you use? (Forms or Control?)
 
Actually I was just using that button as a test. When I got it working I was going to use the code in the Workbook_Open() sub.

Private Sub Workbook_Open()
If OptionButton2 Then
OptionButton1.Value = OptionButton2.Value
End If
End Sub

I have integrated barcodeing into my program. And would like it to be off by default, even if it was left on when they saved it.

I had it working with the button to change it to off. But I could not get it to work when I opened the workbook.....
Any sugestions?
 
Thank you very much :) Very Helpful!!
 
Skip,

I'm getting nuthin' in the Office 03 forum matching &quot;EXCEL HELP BADLY&quot; - a yanked thread???

I trust it was more in the line of amusing commentary than need-to-know info. . . [LOL]

VBAjedi [swords]
 
You didn't answer my question as to which tool bar you used for the OptionButton.

Assuming you used the Control Toolbox, the easiest way is to use the &quot;LinkedCell&quot; property of the OptionButtons and then use code like this (building on Skip's suggestion)

If button 1 is linked to cell H2 on &quot;Sheet1&quot; then on the code page for the workbook:
Code:
Private Sub Workbook_Open()
  InitObjects
End Sub
And in a separate code module:
Code:
Sub InitObjects()
  Worksheets(&quot;Sheet1&quot;).Range(&quot;H2&quot;) = True
End Sub
Although, if you prefer, you can just as effectively put it all in the Workbook code page:
[blue]
Code:
Private Sub Workbook_Open()
  Worksheets(&quot;Sheet1&quot;).Range(&quot;H2&quot;) = True
End Sub
[/color]


 
Private Sub Workbook_Open()
Worksheets(&quot;Daily&quot;).OptionButton1.Value = True
End Sub

This is the code that worked for me!!
Thanks for all the help! Oh yeah, yes it is an option button from the Control Toolbox. Thanks again!

BENCNU

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top