Conflicting Click and DblClick events

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,164
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 ?
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,414
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,164
Office Version
  1. 2016
Platform
  1. Windows
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 .
 

Watch MrExcel Video

Forum statistics

Threads
1,126,986
Messages
5,621,992
Members
415,873
Latest member
fuulhouse

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
Top