KeyPress Event Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Saunders

    KeyPress Event Question

    I have a text box for entering in a search string on my form. I coded the
    following KeyPress event handler:

    Private Sub txtFindCall_Key Press(KeyAscii As Integer)

    If KeyAscii = 13 Then
    cmdFind_Click
    Exit Sub
    End If

    End Sub

    This allows the user to start the search by hitting the Enter key while in
    this text box. It works fine but my PC sounds a beep when Enter is pressed.

    Can I turn this off? What does it signify?

    Thanks,

    Stephen Saunders

    P.S. Thanks to those who answered my "Repeat Question" post!


  • Rick Rothstein

    #2
    Re: KeyPress Event Question

    > I have a text box for entering in a search string on my form. I coded
    the[color=blue]
    > following KeyPress event handler:
    >
    > Private Sub txtFindCall_Key Press(KeyAscii As Integer)
    >
    > If KeyAscii = 13 Then
    > cmdFind_Click
    > Exit Sub
    > End If
    >
    > End Sub
    >
    > This allows the user to start the search by hitting the Enter key[/color]
    while in[color=blue]
    > this text box. It works fine but my PC sounds a beep when Enter is[/color]
    pressed.[color=blue]
    >
    > Can I turn this off? What does it signify?[/color]

    Yes, you can turn it off by adding this line to the If-Then block

    KeyAscii = 0

    The reason it beeps is because the MultiLine property is set to False.
    If the TextBox can only have a single line, then hitting Enter (go to
    next line) is considered an error; hence, the beep.


    Comment

    • Rick Rothstein

      #3
      Re: KeyPress Event Question

      > I have a text box for entering in a search string on my form. I coded
      the[color=blue]
      > following KeyPress event handler:
      >
      > Private Sub txtFindCall_Key Press(KeyAscii As Integer)
      >
      > If KeyAscii = 13 Then
      > cmdFind_Click
      > Exit Sub
      > End If
      >
      > End Sub
      >
      > This allows the user to start the search by hitting the Enter key[/color]
      while in[color=blue]
      > this text box. It works fine but my PC sounds a beep when Enter is[/color]
      pressed.[color=blue]
      >
      > Can I turn this off? What does it signify?[/color]

      Yes, you can turn it off by adding this line to the If-Then block

      KeyAscii = 0

      The reason it beeps is because the MultiLine property is set to False.
      If the TextBox can only have a single line, then hitting Enter (go to
      next line) is considered an error; hence, the beep.


      Comment

      Working...