Solved

highlighting Visual Basic textbox

Posted on 2000-02-23
10
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses
Course of the Month6 days, 5 hours left to enroll

626 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