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

Option Button = True (but not clicking!) 1

Status
Not open for further replies.

Welshbird

IS-IT--Management
Jul 14, 2000
7,378
DE
Hi all,

I want to set an option button to be TRUE as part of initialising my form.

However, the user can obviously still click on this button if they want (this is one of a group of three buttons - I want to prepopulate the form with the last chosen options which are taken from cells in a hidden sheet).

But, when I set the option button to be true the code for optButton_Click is activated.

HOw can I set by option button to be true without it thinking I just clicked it now??

Fee

"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen
 
Sadly (in this case) that's the documented behaviour.

One work around is to use a mutex.

Example. Create a flag variable whose scope is for the entire userform.

e.g.
Code:
[blue]Option Explicit

Private SettingFromCode As Boolean

Private Sub CommandButton1_Click()
    SettingFromCode = True
    OptionButton1.Value = True
    SettingFromCode = False
End Sub

Private Sub OptionButton1_Click()
    If Not SettingFromCode Then
        MsgBox "Clicking, not coding"
    End If
End Sub[/blue]

 
Perfect!

(I should have been able to think of that I suspect, but am loving it as a solution!)

Fee

"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen
 
If it is to be the default value, it can be done in design mode (check the 'Value' property).

combo
 
It's based on the value in a cell in a hidden worksheet - so that I can make the form 'remember' what the user chose last time.

Strongm's solution is perfect though.

Fee

"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top