[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

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-
0
ShelfieldCollege
Asked:
ShelfieldCollege
  • 3
  • 2
2 Solutions
 
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
 
fds_fatboyCommented:
Alternatively, you could make cmdSend the default button. This would be more standard.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now