Avoid beeps on forms without a default button

Avoid beeps on forms without a default button

If a form contains one CommandButton control whose Default property is set to True, the Enter key activates the CommandButton. If the form doesn’t contain any default CommandButton control, however, pressing the Enter key when the focus is inside a TextBox control (and a few other controls as well) results in an annoying beep.

You can get rid of this beep by setting the form’s KeyPreview property to True and adding the following code routine:

Private Sub Form_KeyPress(KeyAscii As Integer)    ' check the type of the control that is currently active    If TypeOf ActiveControl Is TextBox Then        ' discard the Enter key        If KeyAscii = vbKeyReturn Then KeyAscii = 0    End IfEnd Sub

See also  5 Tips for Choosing the Right Medical Software for Your Practice

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist