[RESOLVED] CTRL+A - Select All: Beep sound?
Is there a way to get rid of that beep sound when using CTRL+A to select all text in a textbox?
I'm using this code, with the Form's KeyPreview property set to True.
vb Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = vbCtrlMask Then
If KeyCode = vbKeyA Then
Control_SelectAll Me.ActiveControl
End If
End If
End Sub
Public Sub Control_SelectAll(ByRef ControlObject As Control)
On Error Resume Next
With ControlObject
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
Re: CTRL+A - Select All: Beep sound?
Try setting KeyCode and Shift to 0 after calling your routine, as that will indicate that you have dealt with the key press.
Re: CTRL+A - Select All: Beep sound?
You need to handle the KeyPress event as well. It occurs in addition to the KeyDown and KeyUp events but allows you to cancel a key stroke by setting it's KeyAscii argument to 0.
The KeyAscii value of a Ctrl+Letter key is from 1(A) to 26(Z)
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If TypeOf Me.ActiveControl Is VB.TextBox Then
Select Case KeyAscii
Case 3, 8, 22, 24 'Allowable control keys in a textbox ctrl-C, ctrl-H (backspace), ctrl-V, ctrl-X
Case Is < 27
KeyAscii = 0
End Select
End If
End Sub
Re: CTRL+A - Select All: Beep sound?
Quote:
Originally Posted by
si_the_geek
Try setting KeyCode and Shift to 0 after calling your routine, as that will indicate that you have dealt with the key press.
Yeah, I tried that first and didn't work. :(
Quote:
Originally Posted by
brucevde
You need to handle the KeyPress event as well. It occurs in addition to the KeyDown and KeyUp events but allows you to cancel a key stroke by setting it's KeyAscii argument to 0.
The KeyAscii value of a Ctrl+Letter key is from 1(A) to 26(Z)
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If TypeOf Me.ActiveControl Is VB.TextBox Then
Select Case KeyAscii
Case 3, 8, 22, 24 'Allowable control keys in a textbox ctrl-C, ctrl-H (backspace), ctrl-V, ctrl-X
Case Is < 27
KeyAscii = 0
End Select
End If
End Sub
Thanks. I just added the If KeyAscii < 27 part and it fixed it. :cool:
Re: [RESOLVED] CTRL+A - Select All: Beep sound?
Quote:
I just added the If KeyAscii < 27 part and it fixed it.
Just to be sure you understand that without the Case 3,8,22,24 line the user won't be able to delete anything using the Backspace key nor do any Cut/Paste/Copy operations. Those keys will not cause a Beep because they are valid keystrokes in the TextBox.
If that is allright then :thumb:
Re: [RESOLVED] CTRL+A - Select All: Beep sound?
Quote:
Originally Posted by
brucevde
Just to be sure you understand that without the Case 3,8,22,24 line the user won't be able to delete anything using the Backspace key nor do any Cut/Paste/Copy operations. Those keys will not cause a Beep because they are valid keystrokes in the TextBox.
If that is allright then :thumb:
Hm, I had no idea about the 3, 22, or 24. Thanks. :cool: