PDA

View Full Version : Select all text of a textbox



dansam
02-23-2007, 09:15 AM
Hi everyone,
I want that when a user clicks or focus on the textbox1, it automatically selects all text in the textbox1, so any idea? :think:
Regards,
Dan

lucas
02-23-2007, 09:27 AM
Not sure how to do this on click or focus but this works for when the userform is initialized:
Option Explicit
Private Sub UserForm_Initialize()
Me.TextBox1.Text = "Optional text"
Me.TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
End Sub

Thanks to Tommy for this bit

dansam
02-23-2007, 09:43 AM
Hi,
It worked but what to do to do this same thing on focus?
dan

lucas
02-23-2007, 10:02 AM
good question.....I don't know. Maybe someone else has an idea.

lucas
02-23-2007, 10:29 AM
Dan,
If you can get them to use the enter key: see attached

I'll take another look at the setfocus....

lucas
02-26-2007, 09:05 AM
Bump for fresh ideas.......

moa
02-26-2007, 09:14 AM
set the enterfieldbehaviour property to 0

dansam
02-26-2007, 09:46 AM
Hi

set the enterfieldbehaviour property to 0
It’s already at 0 !!!!!
Any chance for on focus property or may be using send keys “ctrl + a” to select all text on click ??????

moa
02-27-2007, 08:05 AM
I can't actually download anything at work so I haven't looked at Lucas's code but if it needs a return key press you could use sendkeys ("~") to do that. Might work if it was in the Enter event of the textbox but I have my doubts as sendkeys is weird in certain situations.

Anyway, hope you find your answer...

dansam
02-27-2007, 08:19 AM
ya,
thanks for suggestion !
dan