none
"Control-A" = "Select All Text"

    Question

  • When the focus is on a "Text Box", whether the Control Source is a simple text or memo, when I enter a Control-A, I was expecting that it would "Select All Text".  But it appears to move from my current record to the first record of the Dataset.

     

    Is there any way to change it so the Control-A acts like a "Select All Text", whether on a database application level or on a form (or other) level without having to check each character the user types in?

     

    TIA

    Saturday, October 08, 2011 8:43 PM

Answers

  • Another thought is to write an AutoKeys macro to intercept Ctrl+A. Then work with properties like Form.ActiveControl to check if it is a textbox and if so select all text.
    -Tom. Microsoft Access MVP
    • Marked as answer by bhata Sunday, October 09, 2011 2:49 AM
    Saturday, October 08, 2011 11:29 PM
  • Another thought is to write an AutoKeys macro to intercept Ctrl+A. Then work with properties like Form.ActiveControl to check if it is a textbox and if so select all text.
    -Tom. Microsoft Access MVP


    Perfect!  Thanks Tom!!!

    After searching how to create AutoKeys I created the macro:

     

      Macro Name    ^a
      Action             RunCode
      Arguments       AutoKeys_ControlA()
    


    Then I wrote a Function:

    Public Function AutoKeys_ControlA()

    Dim curControl As Control Dim controlType As Integer ' get the control that currently has focus Set curControl = Screen.ActiveControl ' if current control is a Text Box controlType = curControl.Properties("ControlType") If (controlType = acTextBox) Then ' select the text in the Description control 'curControl.SetFocus curControl.SelStart = 0 curControl.SelLength = Len(curControl.Text) End If ' endif - current control is a Text Box
    End Function


    So now it works for TextBox's in my software!!!

    Woo Hoo!!!

    • Marked as answer by bhata Sunday, October 09, 2011 2:49 AM
    Sunday, October 09, 2011 2:48 AM

All replies

  • When the focus is on a "Text Box", whether the Control Source is a simple text or memo, when I enter a Control-A, I was expecting that it would "Select All Text".  But it appears to move from my current record to the first record of the Dataset.

     

    Is there any way to change it so the Control-A acts like a "Select All Text", whether on a database application level or on a form (or other) level without having to check each character the user types in?

     

    TIA


    Well, I did a test and defined an KeyPress event on the Form and on the Text Box.  Also I verfied that the Form's KeyPreview is "Off".

     

    When I entered "x", it goes to the Text Box's event.

    When I entered "Control-A" it goes to the Form's event.

     

    Also, after entering the "Control-A", the focus moves to some unknown location.  I try to find the control that has focus by using:

      Form.ActiveControl.Name

      Screen.ActiveControl.Name

    but in both circumstances I get a Run-Time error '2474', "The expression you entered requires the control to be in the active window.

     

    This is frustrating!  Help!

     

    Saturday, October 08, 2011 9:11 PM
  • Control+A seems to select all records in the form's record source. You would probably need to trap for a different key stroke like Ctrl+Z

    Private Sub Text0_KeyPress(KeyAscii As Integer)
        If KeyAscii = 26 Then 'ctrl+z
            KeyAscii = 0  'cancel the KeyAscii
            Screen.ActiveControl.SelStart = 0
            Screen.ActiveControl.SelLength = Len(Screen.ActiveControl.Text)
        End If
    End Sub


    Duane Hookom MS Access MVP 2001 to Present
    Saturday, October 08, 2011 10:09 PM
  • Control+A seems to select all records in the form's record source. You would probably need to trap for a different key stroke like Ctrl+Z

    Private Sub Text0_KeyPress(KeyAscii As Integer)
        If KeyAscii = 26 Then 'ctrl+z
            KeyAscii = 0  'cancel the KeyAscii
            Screen.ActiveControl.SelStart = 0
            Screen.ActiveControl.SelLength = Len(Screen.ActiveControl.Text)
        End If
    End Sub


    Duane Hookom MS Access MVP 2001 to Present


    My point is, I (and most users) would not think to use any other key to "Select All Text", especially since Control-C and Control-V works as it does in other Microsoft applications...

     

    Any other thoughts to get this to work?  I'm getting to the point where even a messy solution is welcomed...

     

     

    Saturday, October 08, 2011 10:17 PM
  • Another thought is to write an AutoKeys macro to intercept Ctrl+A. Then work with properties like Form.ActiveControl to check if it is a textbox and if so select all text.
    -Tom. Microsoft Access MVP
    • Marked as answer by bhata Sunday, October 09, 2011 2:49 AM
    Saturday, October 08, 2011 11:29 PM
  • I agree with Tom but didn't try it.

    I wonder why the question. I have never had a need to select all text in a control. I've never had a user ask for functionality like this. As a matter of fact, I doubt most of my users have ever intentionally used select all.


    Duane Hookom MS Access MVP 2001 to Present
    Sunday, October 09, 2011 12:53 AM
  • Another thought is to write an AutoKeys macro to intercept Ctrl+A. Then work with properties like Form.ActiveControl to check if it is a textbox and if so select all text.
    -Tom. Microsoft Access MVP


    Perfect!  Thanks Tom!!!

    After searching how to create AutoKeys I created the macro:

     

      Macro Name    ^a
      Action             RunCode
      Arguments       AutoKeys_ControlA()
    


    Then I wrote a Function:

    Public Function AutoKeys_ControlA()

    Dim curControl As Control Dim controlType As Integer ' get the control that currently has focus Set curControl = Screen.ActiveControl ' if current control is a Text Box controlType = curControl.Properties("ControlType") If (controlType = acTextBox) Then ' select the text in the Description control 'curControl.SetFocus curControl.SelStart = 0 curControl.SelLength = Len(curControl.Text) End If ' endif - current control is a Text Box
    End Function


    So now it works for TextBox's in my software!!!

    Woo Hoo!!!

    • Marked as answer by bhata Sunday, October 09, 2011 2:49 AM
    Sunday, October 09, 2011 2:48 AM
  • I wonder why the question. I have never had a need to select all text in a control. I've never had a user ask for functionality like this. As a matter of fact, I doubt most of my users have ever intentionally used select all.


    My application is for a photo archives database.  The photos came from a professional studio in which they take one or more additional photos with the same subjects. 

    In the database when the Description field for one photo is typed in, many times one or more additional photos will have the same description.  Having Ctrl-A / Ctrl-C / Ctrl-V capability is important in this application.

    Sunday, October 09, 2011 3:11 AM