I want to disable the command Ctrl + A (select all) in Access 2007. Is that possible?
5 Answers
You can use this code in Access to catch CTRL+A and ignore it. The downside is you will have to add this to every form you wish to block. (the upside: you don't have to block every form)
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyA And Shift = acCtrlMask Then 'Catch Ctrl+A
KeyCode = 0 'Suppress keypress
End If
End Sub
Add this to the Form > On Key Down Event
IMPORTANT: Scroll to the bottom of the Event list and change Key Preview to Yes.
Create a macro called AutoKeys. In the first column, type ^A, and in the second, choose Beep from the dropdown. This will cause a Beep anytime ^A is pressed anywhere in your app.
If you want to do absolutely nothing (i.e., no BEEP), you'll have to write a function to call that does nothing and call that with the RunCode action.
If you want to allow it in some contexts and not in others, you'd have to write more complicated code for that. I'm not entirely sure what that code would look like as it raises a number of interesting problems.
And, of course, that's a StackOverflow question...
(frankly I think this whole question belonged over there all along, since the answers require either writing coding or creating something code-like, i.e., a macro)
- 984
#IfWinActive, ahk_class OMain
^a::Return
#IfWinActive
In the Autohotkey automation language.
Alternatively:
#IfWinActive, ahk_class OMain
^a::MsgBox, Oh god oh god we're all going to die
#IfWinActive
- 23,483
I don't think so. That key combination is the same in most packages (not just MS ones) and is defined at a fairly basic level.
Of course this is where someone else comes in and proved me wrong
- 41,540
The following code selects all the TEXT in a textbox or combo box (instead of selecting the entire table).
Use this code in form KeyDown event, and don't forget to also set "Key Preview" property in form event properties to Yes (otherwise it won't trigger the keydown event for CTRL + A).
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyA And Shift = acCtrlMask Then
If TypeOf Me.ActiveControl Is TextBox Then
Dim txt As TextBox
Set txt = Me.ActiveControl
txt.SelStart = 0
txt.SelLength = Len(txt.text)
ElseIf TypeOf Me.ActiveControl Is ComboBox Then
Dim cmb As ComboBox
Set cmb = Me.ActiveControl
cmb.SelStart = 0
cmb.SelLength = Len(cmb.text)
End If
KeyCode = 0 ' Cancel the default action (of selecting the entire table)
End If
End Sub
- 121