Option Buttons in Userform

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Okay,

I'm having a massive problem trying to setup a couple of Option Buttons in my userform. Basically I have the following code that depending on which option button is TRUE, will enable or disable parts of the userform...

Code:
Private Sub obPolicyDetails1_Change()

    Call AmountOfCover

End Sub

Private Sub obPolicyDetails2_Change()

    Call AmountOfCover

End Sub

Private Sub AmountOfCover()

    If obPolicyDetails1.Value = True And obPolicyDetails2.Value = False Then
        lblPolicyDetails10.Enabled = False
        lblPolicyDetails13.Enabled = False
        txtPolicyDetails2.Enabled = False
        txtPolicyDetails2.BackColor = &HF0F0F0
        lblPolicyDetails11.Enabled = True
        lblPolicyDetails14.Enabled = True
        txtPolicyDetails3.Enabled = True
        txtPolicyDetails2.BackColor = &HFFFFFF
        Exit Sub
    End If
    
    If obPolicyDetails1.Value = False And obPolicyDetails2.Value = True Then
        lblPolicyDetails10.Enabled = True
        lblPolicyDetails13.Enabled = True
        txtPolicyDetails2.Enabled = True
        txtPolicyDetails2.BackColor = &HFFFFFF
        lblPolicyDetails11.Enabled = False
        lblPolicyDetails14.Enabled = False
        txtPolicyDetails3.Enabled = False
        txtPolicyDetails2.BackColor = &HF0F0F0
        Exit Sub
    End If
    
    If obPolicyDetails1.Value = False And obPolicyDetails2.Value = False Then
        lblPolicyDetails10.Enabled = False
        lblPolicyDetails13.Enabled = False
        txtPolicyDetails2.Enabled = False
        txtPolicyDetails2.BackColor = &HF0F0F0
        lblPolicyDetails11.Enabled = False
        lblPolicyDetails14.Enabled = False
        txtPolicyDetails3.Enabled = False
        txtPolicyDetails2.BackColor = &HF0F0F0
        Exit Sub
    End If

End Sub

But I'm finding that the Option Buttons are NOT populating their control sources on first click, the first click looks to be setting the focus, requiring a second click to "put the dot in the hole" ;) which is setting the TRUE and FALSE values in the background.

Does anyone have any tips for setting up Option Buttons like this properly?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,215,790
Messages
6,126,921
Members
449,348
Latest member
Rdeane

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top