Full Version: Click Vs Double Click
UtterAccess Forums > Microsoft® Access > Access Forms
Hello all
I have a button on a form in which the associated code is in the Click event. The button works fine except when some over exuberant users double click the button in this case the the click event is executed twice. I put a msgbox in the double click event to see when it is executed and it seems the order of execution is:
Click 1, the click event is executed
Click 2(the double click), msgbox pops up, then the click event is executed again.
Is there any way I can trap/stop the click event being executed a second time on a double click.
thanks in advance, susie
don't think there's much to be done about it other than teach your users to single click a button instead of double click it (easier said than done, I know).
The only thing I can think of, and I'm not sure it'd be worth the effort, is to setup a timer sequence and a module level flag to indicate if the next click is within your specified "double click" range.
Psuedo-example (complete aircode/concept only!):
Option Explicit
Private bIsDCRange As Boolean
Private Sub Form_Timer()
  bIsDCRange = False
End Sub
Private Button_Click()
  If Not bIsDCRange Then
    'do your stuff
  End If
  bIsDCRange = True
  Me.Timer = SomeNum
End Sub

edit (ok, maybe it would be worth the effort, it seems a little easier than I first thought)
If the sequence is single, double, single. Maybe set a switch in the double.
FOr you could have a switch variable that would exit the subroutine every other time the button is clicked. Of course when a legitimate even-numbered click is made, nothing will happen. But the user will just click again.
Also, if there is any way you can determine the result of the click and if it's done (in time), exit.
You could encapsulate it all within the Click event procedure too.
Private Button_Click()
    Static slgTimer As Single
    Const cSecs = 1
    If Timer - slgTimer > cSecs Then
        'do your stuff
    End If
    slgTimer = Timer
End Sub

Assuming that a second is sufficient interval. (Change the constant as required.)
You could also set focus to another control and disable the button until some other action is performed. (Presumably there needs to be a reason for the button to be clicked - a status set or such...)
John Spencer
You might try
Private Sub MyButton_Click()
   Me.MyButton.Enabled = False
   'execute your code
   Me.MyButton.Enabled = True
End Sub

This should work unless the code you execute is so fast that the user's double-click can still be interpreted as two-clicks
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.