Results 1 to 26 of 26

Thread: Using vbKeyReturn in KeyPress Event of a TextBox [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    Montreal, Quebec
    Posts
    400

    Resolved Using vbKeyReturn in KeyPress Event of a TextBox [RESOLVED]

    I have a VBapp with a textbox that the user enters numbers into. If they press the return key, I want a sub called. The following code works fine, except for one thing. When the return key is pressed, I get a "ding" sound indicating an error (although the textbox still retains the number entered). I put in an error handler and noticed that an error is generated with each key stroke. The error no. returned is "0" and there is no error description. Can anyone help me to get rid of this annoying bug?
    Code:
    Private Sub txtEdit_KeyPress(KeyAscii As Integer)
    
    'Each keystroke generates an error - text is still put into textbox
    
    'On Error GoTo errhandler
    'errhandler:
        'MsgBox Err.number & " - " & Err.Description
       
        Select Case KeyAscii
            Case vbKeyReturn
                ' When the user hits the return key
                ' this code'll move the next cell or row.
                Call DataEntryCell
                    If booMsgBox = True Then
                        booMsgBox = False
                    End If
                With ActiveGrid
                    If .col + 1 <= .Cols - 1 Then
                        .col = .col + 1
                        Active_FlxCell.col = .col
                    ElseIf .row + 1 <= .Rows - 1 Then
                        .row = .row + 1
                        Active_FlxCell.row = .row
                        '.col = 0
                    Else
                        .row = 1
                        .col = 0
                    End If
                  DataEntryBox ActiveGrid
                End With
        End Select
    
    End Sub
    Last edited by Stan; Dec 8th, 2004 at 09:33 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