Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to separate Click and Double-Click events?

Status
Not open for further replies.

VBAGrandpa

Technical User
Sep 14, 2003
4
US
Good morning,
I have an image control that can be either single-clicked or double-clicked to run 2 different subs. The problem is that a double-click invariably also triggers the single-click sub as well. Is there a way to prevent this from happening? BTW, I have played with the mouse click/doubleclick settings but it made no difference. There must be a way to control this programmaticaly.

Dave G
 
You're right, that's ugly. I've never run into that. I was able to produce an ugly workaround, but somebody must have a better solution. In the meantime, here's mine:

(in your userform code)
Code:
Private Sub Image1_Click()
   Application.OnTime Now + 1 / 3600 / 24, "ClickEvent"
End Sub
Private Sub Image1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
   Image1.Tag = "double"
   txtDebug = txtDebug & "Double-clicked registered!" & vbCrLf
End Sub
(in a general code module)
Code:
Public Sub ClickEvent()
   With ClickTest
      If .Image1.Tag = "" Then
         .txtDebug = .txtDebug & "Click registered!" & vbCrLf
      End If
      .Image1.Tag = ""
   End With
End Sub
Unfortunately, if you make the time delay (set for one second above) much shorter, events get missed (the ontime event never fires).


Rob
[flowerface]
 
Thanks Rob! An ugly workaround is better than none. I will try it and let you know how it turns out.

Thanks again

Dave G
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top