Microsoft KB Archive/78305

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

Article ID: 78305

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition
 * Microsoft Visual Basic for MS-DOS

-



This article was previously published under Q78305



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. The following code will prevent the beep.

' (Set Multiline property to False).

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

Additional query words: return 2.00 3.00

Keywords: kbcode KB78305

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.