[RESOLVED] Prevent user from press 'Enter' twice in a few seconds
Hello,
I'm new on this, hope you can help me. I have an application that change the status on a record once user press "enter", but sometimes user gets desperate and hit the key enter multiple times, when screen comes back, shows multiple records as processed.
Any idea how can I accept the enter code, process and if I get another 'enter' show a message saying "You already press enter, wait for process to finish!"
Thanks for your help
Here's part of my code:
Private Sub KeyDown(KeyCode As Integer)
'If the Initialize prompt is up, then do nothing
If picWait.Visible = True Then Exit Sub
If SeqCK = 1 Then Exit Sub
If KeyCode = 96 Then 'Key is 0 then go decrement by one
Log " O Key - Moving Backward"
BK
ElseIf KeyCode = 13 Then 'Key is Enter then increment by one
Log " ENTER Key - Moving Forward"
'BM
MoveForward
ElseIf KeyCode = vbKeyAdd Then 'Key is Plus / Add key then increment by one
Log " * Key - Moves rebuilds Forward"
'BM
MoveForwardRebuilds
End If
End Sub
Re: Prevent user from press 'Enter' twice in a few seconds
You can use a simple timer.
Code:
Private Sub KeyDown(KeyCode As Integer)
If KeyCode = 13 Then
If Timer1.Enabled = True Then Exit Sub ' timer is active; display another message if desirable
Timer1.Interval = 2000 ' 2 seconds
Timer1.Enabled = True
End If
... rest of your code
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
End Sub
When you change focus to a control where you want such a delay, on the SetFocus event, ensure timer is disabled
Re: Prevent user from press 'Enter' twice in a few seconds
Or ... when you start adding details to the record, clear the textboxes (and the checkboxes etc) which user uses to enter/edit his data. Then add a condition in your update code (the code which is triggered after user pressed Enter) to carry on only if all the fields are filled.
Re: Prevent user from press 'Enter' twice in a few seconds
Thanks a lot for your help, it worked!.
Re: Prevent user from press 'Enter' twice in a few seconds
More possiblities;
Code:
Private Sub Command1_Click()
Command1.Enabled = False
'do stuff
Command1.Enabled = True
End Sub
Private Sub Command2_Click()
Static busy As Boolean
If Not busy Then
busy = True
'do stuff
busy = False
End If
End Sub