Conflicting Click and DblClick events

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,806
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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

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