Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

How to force selection of all current text in textbox control on     entry?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chrisso - 25 Nov 2007 19:25 GMT
Hi All

I have a text box on a form. When the user selects the text box it is
*always* to completely change the value. Therefore I would like to
program an event that selects all the current text in the text box
when the user selects it - that way they are ready immediately to
begin typing the new value.

Hoever I cannot get this to work:

Private Sub txtCanvasSizeWidth_Enter()
   Me.txtCanvasSizeWidth.SelStart = 0
   Me.txtCanvasSizeWidth.SelLength = Len(Me.txtCanvasSizeWidth)
End Sub

Can anyone help? Thanks in advance for any ideas?

Chrisso
JLGWhiz - 25 Nov 2007 21:09 GMT
Try putting it in the initialize evert.  I used this code and it worked.

Private Sub UserForm_Initialize()
   TextBox1.MultiLine = True
   TextBox1.EnterFieldBehavior = _
   fmEnterFieldBehaviorRecallSelection
   TextBox1.Text = "Type your text here. " _
   & "Use CTRL+ENTER to start a new line."
   Me.TextBox1.SelStart = 0
   Me.TextBox1.SelLength = Len(Me.TextBox1)
End Sub

> Hi All
>
[quoted text clipped - 14 lines]
>
> Chrisso
Rick Rothstein (MVP - VB) - 25 Nov 2007 21:55 GMT
If your user Tabs into the TextBox, it will automatically select all the
text without you having to do anything; so I presume you are talking about
selecting the TextBox using the mouse. If so, try putting the code you
posted into the MouseDown event for the TextBox and see if that is the
effect you are after. (You could put it in the MouseUp event, and logic
would almost dictate that to be the correct event to use; however, the
selection method is more instantaneous using the MouseDown event.)

Rick

> Hi All
>
[quoted text clipped - 14 lines]
>
> Chrisso
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.