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-
LVL 4
ShelfieldCollegeAsked:
Who is Participating?
 
fds_fatboyCommented:
Alternatively, you could make cmdSend the default button. This would be more standard.
0
 
edwardiiiCommented:
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
0
 
edwardiiiCommented:
Sorry--my workspace is a bit noisy today, so it was still beeping.  Per the above URL, add the following to your Text box's KeyPress event and leave your current KeyUp code as is:

     If KeyAscii = 13 Then
         KeyAscii = 0
    End If

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
fds_fatboyCommented:
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.
0
 
ShelfieldCollegeAuthor Commented:
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-
0
 
edwardiiiCommented:
Thanks very much.  My solution was intended for actuating a button only if no default button was set:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.