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

Time:05-06

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?

CodePudding user response:

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 to be 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.

CodePudding user response:

You can try this code under the double click event of the button

    Private Sub Command1_DblClick(Cancel As Integer)
    Cancel = True
    End Sub

In my case the command button name is Command1

  • Related