Does KeyPress event trap "Backspace" key?

according to VBA-Help KeyPress event can occur when BACKSPACE key is pressed. but it doesn't occur in my code. why can it happen


Answer this question

Does KeyPress event trap "Backspace" key?

  • lchase4411

    Code is following:

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
      Select Case KeyAscii
          Case 8
            MsgBox KeyAscii
          Case 27
            MsgBox KeyAscii
          Case Asc("1") To Asc("9")
            MsgBox KeyAscii
          Case Else
            KeyAscii = 0
      End Select
    End Sub

    Then I press BACSPACE or ESC nothing happen. why


  • Craig Guyer - MSFT

    per our support engineer:

    All of the documents have some problem. KeyPress can’t capture the backspace event.

    Only KeyDown can do it.

    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

    MsgBox KeyCode

    End Sub

    Regards, Xiang

     

    -brenda (ISV Buddy Team)



  • Joseph Kasende

    can you share a sample of your code for us to test out

    thanks,
    -brenda (ISV Buddy Team)



  • Does KeyPress event trap "Backspace" key?