vbams-accessms-access-forms

How can I cancel a button's action on an Access form if the button is double clicked?


I have a MS Access database that has a switchboard on it that opens different forms within the database. For some reason, some of the users like to double click the buttons that open the different forms. This is a problem because one of the forms that opens happens to have a checkbox right where the button that opens it is, so when they double click the button to open the form, it causes the checkbox to toggle and change it's value. It's a constant problem.

I tried adding a double click event handler that would essentially do nothing, but it's not firing and the form still opens and the checkbox keeps getting toggled.

I've tried user education, I've tried telling them that it's causing problems, but they don't seem to get it. Is it possible to only let a button work when it's clicked one time, and if it's clicked twice it just doesn't work, or it throws an error at them to shame them?


Solution

  • One way to solve this is:

    When the second forms opens set the following properties in Form_Open:

    Private Sub Form_Open(Cancel As Integer)
        Me.AllowEdits = False   ' Will prevent form from being edited
        Me.TimerInterval = 500  ' Will trigger Form_Timer after 500 miliseconds
    End Sub
    

    and in the Form_Timer event (kicks in after 500 miliseconds)

    Private Sub Form_Timer()
        Me.AllowEdits = True    ' Allow edit again
        Me.TimerInterval = 0    ' Stop timer
    End Sub
    

    With this the second form will not be possible to edit the first half a second while the second click comes.