Results 1 to 5 of 5

Thread: [RESOLVED] Prevent user from press 'Enter' twice in a few seconds

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    3

    Resolved [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

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    Pakistan
    Posts
    388

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    3

    Re: Prevent user from press 'Enter' twice in a few seconds

    Thanks a lot for your help, it worked!.

  5. #5
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    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
  •  



Click Here to Expand Forum to Full Width