Solved

highlighting Visual Basic textbox

Posted on 2000-02-23
10
323 Views
Last Modified: 2013-11-25
Is there a way of highlighting a textbox when the textbox receives the focus?  

I have a textbox with a value in it and when I tab into that textbox, I want to highlight it so that I can just type and it will erase the text that was in there and replace it with the new text.  

Thanks
0
Comment
Question by:Taitor
  • 5
  • 4
10 Comments
 
LVL 7

Accepted Solution

by:
kamall earned 50 total points
ID: 2552885
Use:

Private Sub Text1_GotFocus()

    Text1.SelLength = Len(Text1)

End Sub

Regards.
0
 
LVL 7

Expert Comment

by:kamall
ID: 2552891
Better, use this code:

Private Sub Text1_GotFocus()

    Text1.SelStart = 0
    Text1.SelLength = Len(Text1)

End Sub

0
 
LVL 6

Expert Comment

by:Marine
ID: 2552894
this is simple but maybe better approaches found.
this goes into getfocus of textbox event
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 6

Expert Comment

by:Marine
ID: 2552897
GRR i hate when that happends.
0
 
LVL 7

Expert Comment

by:kamall
ID: 2552908
Marine,
What is the difference between my code and yours!!!
0
 
LVL 6

Expert Comment

by:Marine
ID: 2552939
absolutely none. the thing is i had a window with a question open earlier but entered results later then you did so i didn't see your posted answer before i submited mine.
0
 

Author Comment

by:Taitor
ID: 2552945
kamall

That seems to work good.

Thanks  
0
 
LVL 7

Expert Comment

by:kamall
ID: 2552955
Taitor,
you are welcome.

Marine,
It always happens to all of us :-)
0
 
LVL 6

Expert Comment

by:Marine
ID: 2552963
i like this board, i learn a lot from it so if i can help in any way its good for me even if someone beats me to it :) I read your profile you got lots of years experience thats really good. Maybe some day i am going to be just as an experienced :-). Catch you later.
0
 
LVL 7

Expert Comment

by:kamall
ID: 2552980
Marine,
I hope you all the success in your future :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question