OptionButtons

sapka

Board Regular
Joined
Nov 9, 2009
Messages
110
Please download attached Excel file. You will find one UserForm there, run it.
Two times select option 2 and choose "No" and close UserForm.

1. Why I am asked "Change it?" just after UserForm loads (no selections are made)?
2. More importantly, why I am two times asked "Change it?" when closing the UserForm?

I do not want any of those events to happen. How to fix it?

File: http://www.2shared.com/file/xRUKUaul/userform.html
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Your current code affecting Option1 is:

Rich (BB code):
Dim DisableEvents As Boolean
 
Private Sub UserForm_Activate()
    DisableEvents = True
    OptionButton1 = True
    DisableEvents = False
End Sub
 
Private Sub OptionButton1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    If DisableEvents Then Exit Sub
    If MsgBox("Change it? Yes/No", vbYesNo) = vbYes Then OtherFunction Else Cancel = True
End Sub

The reason that you get the Msgbox before any selections are made is that the UserForm_Activate has already set the DisableEvents=False before OptionButton1_BeforeUpdate event occurs. To tell VBA to wait until all other events are completed before continuing with _Activate, you could add a DoEvents statement...
Rich (BB code):
Private Sub UserForm_Activate()
    DisableEvents = True
    OptionButton1 = True
    DoEvents
    DisableEvents = False
End Sub

The multiple prompts you are getting are due to the use of the _BeforeUpdate event. I'd suggest you change your triggering event from OptionButton1_BeforeUpdate to OptionButton1_Click. This will provide one check for your MsgBox("Change it? Yes/No.... statement.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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