Link to home
Start Free TrialLog in
Avatar of ShelfieldCollege
ShelfieldCollege

asked on

Textbox KeyUp event prevent annoying beep when enter is pressed.

Hi there, I have a single line textbox calls txtOut and in the KeyUp event I have the following code:

Private Sub txtOut_KeyUp (KeyCode As Integer, Shift as Integer)
    If KeyCode = 13 Then
        Call cmdSend_Click
    End If
End Sub

As you can see the code calls the click event of the cmdSend button should the user press the return key whilst their focus is in the txtOut text box, however if they do this a small annoying beep is sounded (presumably as they are pressing return in a single line textbox and vb is notifying them that they shouldn't do this).  Is there anyway to prevent this beep from sounding?

Cheers

-Matt-
Avatar of edwardiii
edwardiii

Hi, Shelfield_College.

Adding "KeyAscii = 0" works for me. Taken from MSDN (http://support.microsoft.com/default.aspx?scid=kb;en-us;140882):

   If KeyCode = 13 Then
        KeyAscii = 0
        Call cmdSend_Click
    End If
SOLUTION
Avatar of edwardiii
edwardiii

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I should have said that then you would not need to bother with any code to call the button click, or in the Keyup event handler.
Avatar of ShelfieldCollege

ASKER

Cheers, both methods worked perfect.  Use of the default button is probebly the more ideal solution, however knowing how to stop that annoying beep by another method is great too.

Increased points and split between both parties :) Cheers folks

-Matt-
Thanks very much.  My solution was intended for actuating a button only if no default button was set:)