more user form questions - option button events

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
What is the difference between

Private Sub OptionButton7_Click()

and

Private Sub OptionButton7_Change()

Edit - other than the fact that I put the first in red :oops:
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi

Code associated with the first one will run when it is clicked. Code from the second will only run when it is change. So if you click the optionbutton, but don't change it, then nothing will happen.


Tony
 
Upvote 0
I'm not fully sure I understand. No - I am fully sure that I don't understand. I thought an option button can only have two states - clicked or not-clicked. If you click it, then haven't you CHANGED it from being not-clicked?

Gene, "The Mortgage Man", Klein
 
Upvote 0
Code:
Private Sub OptionButton1_Change()
MsgBox "Change"
End Sub

Private Sub OptionButton1_Click()
MsgBox "click"
End Sub

Put 2 buttons on a form and insert the preceeding code .... I think you will see the difference :wink: .

When optionButton1 has been selected you will find that both events fire. However when you now click on another optionbutton only the "Change" event will be fired. This is because the value of the button1 has changed even though you clicked on optionbutton2. :wink:

In other words a value of an option button can be changed , not only by clicking on it , but also by clicking on another button. Since this action will transfer the true value to the newly clicked option button.
 
Upvote 0
Hi

Got that a bit wrong. If you click the button, it will change. But you can change the button without clicking it. So you can get 2 things the click action and the change action. However, if you have 2 buttons, and the first one is selected, then you click the second one, then the first will have the change event, but not the click event.

Go to a spreadsheet and create 2 option buttons. Put in the following code for the option button 1

Code:
Private Sub OptionButton1_Change()
MsgBox "button changed"
End Sub

Private Sub OptionButton1_Click()
MsgBox "button Clicked"
End Sub

When you select option button 1, then you will get 2 messages. However, when you select the second button, you will only get 1 message.


HTH

Tony
 
Upvote 0
In other words a value of an option button can be changed , not only by clicking on it , but also by clicking on another button. Since this action will transfer the true value to the newly clicked option button.

OK - so does this mean if I only use click and never change, then I have restricted the user to picking one and only one button?

Gene, "The Mortgage Man", Klein
 
Upvote 0
Gene

Depends on what you have setup. If you only have one button, then the user doesn't have much choice. If you have multiple buttons, and only code for the click event, it will only action when that button is selected.


Tony
 
Upvote 0

Forum statistics

Threads
1,202,917
Messages
6,052,548
Members
444,591
Latest member
fauxlidae

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