Quick Tip: Preventing Accidental Double-Clicks

Pop quiz, hotshot: What would happen if a user double-clicked every button in your Access application? Would there be any unintended consequences?

Quick Tip: Preventing Accidental Double-Clicks

Have you ever watched your users interact with your Access application?

You'd be amazed at all the things they do that you would never imagine doing yourself.  One common example is double-clicking on buttons.  Some users seem to think that every interaction with the mouse must be performed with a double-click.

Every time I watch this kind of user work with my software I hold my breath.  Will my application break when they double-click on that button?  I never tested that possibility.  Heck, I'd never even considered testing that possibility because it's something that I would never do.  (Incidentally, this illustrates the value of having a good software tester who will absolutely abuse your software to try to break it before your users get a chance to.)

Luckily, it's relatively easy to avoid the negative side effects of users double-clicking buttons that they shouldn't be double-clicking.

The hardest part is remembering to do it.

High-Level Overview

The algorithm is simple and straightforward.  When the user clicks a button:

  1. Disable the button in code
  2. Execute the associated process
  3. Re-enable the button in code

Sample Code

Private Sub YourButton_Click()
    ' Disable the button to prevent double-clicks
    Me.YourButton.Enabled = False
    
    ' Execute the related process
    ' Replace this code with your specific process or actions
    ' For demonstration purposes, we'll display a message box
    MsgBox "Button clicked! Perform your process here."
    
    ' Re-enable the button after the process finishes
    Me.YourButton.Enabled = True
End Sub

A Note About Idempotency

Idempotency refers to the property of an action or operation that can be repeated multiple times without causing additional or different effects after the initial execution.

Accidental double-clicks are especially problematic when the associated process is not idempotent. In a non-idempotent process, running the same action multiple times can lead to undesired outcomes or unintended side effects. For example, imagine a button that creates a new record in the database. If a user accidentally double-clicks on the button, two records would be created.

Thus, one way to avoid problems from accidental user double-clicks is to write idempotent routines whenever possible.


Acknowledgements
  • Portions of this article's body generated with the help of ChatGPT
  • One or more code samples generated with the help of ChatGPTT

All original code samples by Mike Wolfe are licensed under CC BY 4.0