Solved

highlighting Visual Basic textbox

Posted on 2000-02-23
10
293 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now