Conflicting Click and DblClick events

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,619
Office Version
  1. 2016
Platform
  1. Windows
I have a commandbutton (from the ctl toolbbar) embeeded on a worksheet and I noticed that I cannot have a Click and a DblClick events at the same time .

The Click procedure always takes precedence over the DblClick.

Does anybody know of a workaround to this problem ?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
IMO having a click and double-click event violates good UI principles anyway, but I don't know of any way of stopping that sequence.
 
Upvote 0
Thanks Rory for the reply.

I was expecting to make this work by using the GetDoubleClickTime and GetTickCount APIs but the results were inconsistent. To my surprise, just delaying the Click event by 0.1 secs via a simple loop seems to get the job done nicely...To see what I mean, just add a commandbutton to a worksheet and place the following code in the sheet module :

Code:
Option Explicit

Private bDblClicked As Boolean


Private Sub CommandButton1_Click()

    Call Briefdelay(0.1)
    Call DelayedClickEvent

End Sub

Private Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

    MsgBox "DblClick"
    bDblClicked = True

End Sub

Private Sub DelayedClickEvent()

    If bDblClicked Then bDblClicked = False: Exit Sub
    MsgBox "Click"

End Sub

Private Sub Briefdelay(TimeOut As Single)

    Dim t As Single
    
    t = Timer
    Do
        DoEvents
    Loop Until Timer - t >= TimeOut

End Sub

Hope this is consistent .
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

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