How to Disable the ENTER Key BEEP in a VB Text Box

Last reviewed: December 8, 1995
Article ID: Q140882
The information in this article applies to:
  • Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit only, for Windows, version 4.0

SUMMARY

In a Microsoft Visual Basic for Windows text box, the ENTER key causes a warning beep to sound only if the MultiLine property is set to False (the default) and the Warning Beep option is selected in the Sound dialog box of the Windows Control panel.

To disable the beep, in the KeyPress event procedure for the text box, set the value of KeyAscii (which is a parameter passed to KeyPress) equal to zero (0) when the user presses the ENTER key.

MORE INFORMATION

Specifically, use an IF statement to trap the ENTER key and the set KeyAscii to zero (0). Setting the value to zero before the event procedure ends prevents Windows from detecting that the ENTER key was pressed and prevents the warning beep. This behavior is by design and is due to the fact that a non-multiline text box is a Windows default class of edit box.

Example

The following code will prevent the beep.

' (Set Multiline property to False).

Private Sub Text1_KeyPress (KeyAscii as Integer)
   If KeyAscii=13 Then
      KeyAscii=0
   End If
End Sub


Additional reference words: 1.00 return 2.00 3.00 4.00 vb416 vb4win
KBCategory: kbprg kbcode
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 8, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.