Prevent click event from firing twice on doubleclick

I had an issue today where I kept getting error reports from a user. The procedure in question exports a file, and the error report kept saying the file was busy. I told him he couldn’t do a “fresh” export if the file was already open. He insisted it wasn’t and after a while, the root cause suddenly dawned. The user was double clicking the command button, so when the 2nd mouse-click event ran, then obviously the file exported during the first click event was open and busy.

Now one could argue that its a matter of training users, but still, I wondered if there was a simple way to prevent a mouse event from firing twice, if double clicked. And it turns out there was, quite simply in the double-click event of the command button simply put

and your are all set. If you wanted to add some training for the users, you could put a msgbox in there with a sassy message “One click will suffice”

2 comments on “Prevent click event from firing twice on doubleclick
  1. Mark Liquorman says:

    This is one of the few places I use a macro. The macro merely contains the “Cancel Event” action, and is placed in the DblClick property of the command button. Doesn’t require code, is easy to apply to a bunch of command buttons at once, and when I copy a button to another place, the macro stays with it.

    • TheSmileyCoder says:

      Thank you Mark.
      Thats a good idea. It also keeps the code out of the form module, keeping it “cleaner”. Thank you for sharing.

Ask a question, leave some feedback, post a reply!