Solved

For text box...

Posted on 2002-04-15
6
132 Views
Last Modified: 2010-05-02
Suppose I have a textbox control, say Text1. Whenever I focus on the textbox the text will automatically selected(ie. in windows it will be hilighted in blue) and whenever I write on it it deletes the previous content.
Please write some code.

regards
Subhasis
0
Comment
Question by:mitra_subhasis
6 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 10 total points
ID: 6941443
Hi,

Use SendKeys "{Home}+{End}", example:

Private Sub Text1_Click()
    SendKeys "{Home}+{End}"
End Sub

Private Sub Text1_GotFocus()
    SendKeys "{Home}+{End}"
End Sub
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6941445
Private Sub Text1_GotFocus()
 With Text1
  .SelStart = 0
  .SelLength = Len(.Text)
 End With
End Sub
0
 

Expert Comment

by:sweetpillow
ID: 6941527
Hi mitra,

  Try the following code. Suppose I have a text box in the form1 name text1.

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.BackColor = vbWhite
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    Text1.Text = ""
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.BackColor = vbBlue
    Text1.SetFocus
End Sub

Cheers,
Sweetpillow :)
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.

 

Author Comment

by:mitra_subhasis
ID: 6941534
That's very pretty...

Thanking you,'
Subhasis
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6941536
sweetpillow, it would indeed work, however you would need to reset the colours in the KeyDown event otherwise it will still stay white on blue.

Anyway the snippet I posted achieves everything required with less code. ryancys's suggestion would also work but sendkeys is not necessarily the most reliable method.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6941538
Ah well mitra_subhasis, you chose a solution which is your right, I would stand by my last comment that sendkeys is not necessarily the MOST reliable way to achieve this when you can do it more simply with the suggestion I gave!
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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

861 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

23 Experts available now in Live!

Get 1:1 Help Now