Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

Do you know what happens if you are in an Access text box and press Ctrl-A?

You might expect all the text in it to be selected like a text box on a web page or in a Word document. But it doesn’t. If you are in a text box on a form in the normal single form view it appears to do absolutely nothing.

However if you are in datasheet view, it will select all the fields and all the records. Here’s a nice list of shortcuts (including Ctrl-A) collected by Colin Ridington on his web site: https://isladogs.co.uk/keyboard-shortcuts/index.html

So what are the options for selecting all the text in a text box?

One trick I saw on a forum post was to press TAB then Shift-TAB. This moves to the next control then back to the original control. When tabbing between controls the default behavior is for Access to select all the text.

Another option would be to position your cursor at the beginning or end of the text and use a combination of arrow keys, home and/or end while holding down shift.

Yet another option would be to click once on the field so the cursor is placed there with nothing selected and then triple click to select all the text in the box.

But what if you want to change the behavior of Access with VBA code?

I think the general idea would be:

  1. Make sure your form is set to see keystrokes.
  2. Use event handling on jthe form to capture keyboard strokes.
  3. Detect whether Ctrl-A is being pressed.
  4. If so, detect whether you are on a text box control.
  5. If so, abort the Ctrl-A keystroke, set the cursor to the beginning of the text box and select all of the text in the text box using VBA.

That’s pretty much it, but wouldn’t it be great to have that in a class module? You could load the class module in the Open event of your form, run some code to initialize the class which would set the correct parameters on the form and listen for the form’s keyboard stroke event that you can cancel.

Here would be a good place to start. Much of the code is written in this StackOverflow article: vba – How to use Ctrl+A in a MS-Access textbox in order to select all the text – standard module option – Stack Overflow

Let me know if you write a class to do this. If I end up doing that I’ll let you know.