Selecting all textbox text on GotFocus

chrislee

New member
Local time
Today, 23:51
Joined
Aug 19, 2003
Messages
8
I need a way of achieving the following:

When the user clicks onto a textbox, the text displayed in it is automatically highlighted. This already happens when you tab from one field to the next and allows quick overtyping of the field text without the need to highlight first.

Unless there's some hidden property for a textbox I'm not aware of, I'm guessing I'll need some module with a procedure to achieve this. I've experimented in using tbx.SelLength = Nz(Len(tbx), 0) and this works when I use it from a command button. But when I call it from the GotFocus event it doesn't work.

Any suggestions gratefully received!

TIA,

Chris.
 
I think this would have been better posted in the General forum, but here's one way to get the result you'd like.
Create a text Box on your form, set the back style and border style to transparent and the Width/height to "0.00".
In the Click event of the fields you'd like to highlight put the following code...
Code:
Private Sub ThisTextField_Click()

    Me.YourTransparenttextBox.SetFocus
    Me.ThisTextField.SetFocus

End Sub

HTH
IMO
 
Thanks. Can't believe it was that simple! I was trying to work out how to select the text automatically, but your method uses the existing technique which Access already applies when you tab to and from fields.

Most appreciated!

Chris.
 

Users who are viewing this thread

Back
Top Bottom