Userform - Option Button Events

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
In the list that VBA gives you for the possible Option Button Events, I do not see Right Click. (I see click and doubleclick). Is there any way to distinguish between a left and right click (for an Option Button Event)?

Gene, "The Mortgage Man", Klein
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,062
Office Version
  1. 2016
Platform
  1. Windows
mortgageman,

As far as I know, there is no such event for Option Buttons athough some API code could probably achieve a close solution.

What do you want to see when you right click the Option Button anyway ?

Regards.
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
I have programmed The Game of Wari (aka Mandinka) in Excel. In General terms, the user has 6 choices each time s/he moves. I currently use 6 option buttons for this. I thought it would be pretty cool if by clicking on the right button, the user would see the effect of his move without it actually taking effect (I would use a MultiPage control for this I guess).

BTW - Since I could never have done any of this without the help from people on this board, I would be happy to upload the game as it is now if anyone wants it (and I knew how to upload files - which of course I don't)

Gene, "The Mortgage Man", Klein
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
**bump**

So is there no way (other than to have two option buttons for each choice) to handle this feature?

Gene, "The Mortgage Man", Klein
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,222

ADVERTISEMENT

Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
MsgBox "Your left click code goes here", , "Left button"
ElseIf Button = 2 Then
MsgBox "Your right click code goes here", , "Right button"
End If
End Sub
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015

ADVERTISEMENT

Tom (or anyone) quick question: Why are there arguments (Shift, X and Y) that are not used?

Gene, "The Mortgage Man", Klein


Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
MsgBox "Your left click code goes here", , "Left button"
ElseIf Button = 2 Then
MsgBox "Your right click code goes here", , "Right button"
End If
End Sub
_________________
Tom Urtis
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,222
I don't know what you mean by "that are not used". The only reason those parameters would not be used is that you are not referring to them in your code for evaluation of the Shift key or mouse position relative to control at the point of execution.

So, go ahead and use them if you want, example:


Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim ShiftSpeak$
If Val(Shift) = 0 Then
ShiftSpeak = "your keyboard's Shift button was not pressed."
Else
ShiftSpeak = "your keyboard's Shift button was pressed."
End If
MsgBox _
"When you clicked the mouse," & vbCrLf & _
ShiftSpeak & vbCrLf & vbCrLf & _
"Regarding the mouse's location relative to OptionButton1:" & vbCrLf & _
"Mouse position as distance from left: " & Val(X) _
& vbCrLf & _
"Mouse position as distance from top: " & Val(Y), _
64, "MouseDown info for OptionButton1"
End Sub
 

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
Gotta Tom - you hadn't used them, so I wasn't sure what they were. So if i understand you correctly, in this (MouseDown) event, all of those parameters are available to me. Is that it?

Gene


I don't know what you mean by "that are not used". The only reason those parameters would not be used is that you are not referring to them in your code for evaluation of the Shift key or mouse position relative to control at the point of execution.

So, go ahead and use them if you want, example:


Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim ShiftSpeak$
If Val(Shift) = 0 Then
ShiftSpeak = "your keyboard's Shift button was not pressed."
Else
ShiftSpeak = "your keyboard's Shift button was pressed."
End If
MsgBox _
"When you clicked the mouse," & vbCrLf & _
ShiftSpeak & vbCrLf & vbCrLf & _
"Regarding the mouse's location relative to OptionButton1:" & vbCrLf & _
"Mouse position as distance from left: " & Val(X) _
& vbCrLf & _
"Mouse position as distance from top: " & Val(Y), _
64, "MouseDown info for OptionButton1"
End Sub
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,222
mortgageman said:
So if i understand you correctly, in this (MouseDown) event, all of those parameters are available to me. Is that it?
Yep - - they are available to you, to me, and everyone, they are equal opportunity parameters, standard with the OptionButton control's mousedown event for whoever is inclined to invoke their coded services.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,377
Messages
5,571,775
Members
412,419
Latest member
acemali
Top