3

I want to disable the command Ctrl + A (select all) in Access 2007. Is that possible?

5 Answers 5

6

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.

0
2

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)

1
#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
4
  • Where do I put this code?
    – Johan
    Nov 22, 2009 at 15:19
  • Install autohotkey, then make a file with the extension .ahk. Run this file (Put it in startup for best results), and try and control-a :)
    – Phoshi
    Nov 22, 2009 at 15:35
  • 1
    Sound a bit to complicated. The database should work on different computers, so install something else than just access is not an option. Thanks any way.
    – Johan
    Nov 22, 2009 at 15:58
  • You can compile ahk scripts to work without having to install anything, which is less hassle, at least. I don't think you'll find an easier option, but don't give up hope :)
    – Phoshi
    Nov 22, 2009 at 16:03
0

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

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .