Command buttons in VBA "keep pressing" (1 Viewer)

Leo_Polla_Psemata

Registered User.
Local time
Yesterday, 16:32
Joined
Mar 24, 2014
Messages
364
Hi,
when user assigns a code to a command button, he has a large amount of options such as
on click
on double click
on got focus
on lost focus
etc.

Could we make an option that
the command is fired when we click and keep pressing it for more than 3 seconds ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:32
Joined
May 7, 2009
Messages
19,230
what do you mean, you mean triggering the click event while it is being pressed?
look for the property: Auto Repeat = Yes.
 

Leo_Polla_Psemata

Registered User.
Local time
Yesterday, 16:32
Joined
Mar 24, 2014
Messages
364
what do you mean, you mean triggering the click event while it is being pressed?
look for the property: Auto Repeat = Yes.
I mean that, we can either click, or double click. Is there any way we click, keep mouse clicked for an amount of time, say 3 seconds, and if continues clicked 3 seconds the code starts ? I this property: Auto Repeat = Yes. similar ?

My purpose, i have a code that i click (or double click) and update a table, HOWEVER i don't want to set any filters in the table, there is always a risk of click again next day and duplicate all records. Okay, i can get another rule, deactivate button for example iif something , but, a click and keep it pressed for 3' would be safety against wrong click.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:32
Joined
Feb 19, 2013
Messages
16,607
see this link about autorepeat

so think you would need to set a time on first 'iteration' and compare this time to the current time on each subsequent iteration. If the time is greater than the first time, then run your update code. You would also need something to prevent the update code running again if the button continues to be pressed.

Would think simply disabling the button would be much simpler
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:32
Joined
Feb 19, 2002
Messages
43,257
there is always a risk of click again next day and duplicate all records
If you don't know enough not to click in the first place, how is a delay going to help? The way to protect yourself against yourself is to figure out a way to only allow the click once or determine that the button has already been clicked because the records already exist and give an error message to the user.

Using the repeat feature is not the way to do this. If you want to have a confirmation click, then use the double-click event (the click is too easy to do by accident) and In the event code, ask the user to confirm the action so you only do the append if the user answers yes. Of course this gets pretty annoying pretty fast but if it is saving you from yourself, you may decide to just put up with it.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:32
Joined
Feb 28, 2001
Messages
27,172
If you really need to know how long a button is clicked, look at the MouseUp and MouseDown events, though you also have to verify the location of the mouse as being with the rectangle that is the command button. To time the difference between MouseDown and MouseUp, look at the Timer() function, which gives you 60ths of a second resolution.
 

Users who are viewing this thread

Top Bottom