|
-
Nov 22nd, 2011, 03:31 PM
#1
Thread Starter
New Member
[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
-
Nov 22nd, 2011, 04:31 PM
#2
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
-
Nov 22nd, 2011, 11:30 PM
#3
Hyperactive Member
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.
If your problem is solved, then drag down the Thread Tools and mark your thread as Resolved.
If I helped you solve your problem, inflate some air into my ego by rating my post and adding a comment too.
For notorious issues (elaborate yourself) contact me via PM. I don't answer them in the forums EVER.
-
Nov 23rd, 2011, 07:57 AM
#4
Thread Starter
New Member
Re: Prevent user from press 'Enter' twice in a few seconds
Thanks a lot for your help, it worked!.
-
Nov 23rd, 2011, 09:13 AM
#5
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
Last edited by Magic Ink; Nov 23rd, 2011 at 09:17 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|