TextBox Question

J

Jim

How do I put text in a textbox and make it go away as soon as the user clicks
in the field to enter their own information? I know how to put text in the
field but you have to highlight it and delete it if you want to enter new
information.
 
R

Rick Rothstein \(MVP - VB\)

Where did you get the TextBox from? The Drawing Toolbar on the worksheet?
The Control Toolbox toolbar on the worksheet? The Control Toolbox in the VB
editor for placement on a UserForm?

Rick
 
J

Jim

Control Toolbox In VB - A UserForm

Rick Rothstein (MVP - VB) said:
Where did you get the TextBox from? The Drawing Toolbar on the worksheet?
The Control Toolbox toolbar on the worksheet? The Control Toolbox in the VB
editor for placement on a UserForm?

Rick
 
R

Rick Rothstein \(MVP - VB\)

As you know, Tab'bing into the TextBox automatically highlights (selects)
the text by default so that the user can type over (replace) it or click
into it to edit it. You can make a mouse click into the TextBox do the same
thing... will that be acceptable? If so, copy/Paste the following code into
your UserForm's code window...

'*************** START OF CODE ***************
Dim ClickedOnceAlready As Boolean

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ClickedOnceAlready = False
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not ClickedOnceAlready Then
ClickedOnceAlready = True
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
'*************** END OF CODE ***************

Rick
 
J

Jim

Thanks, I modified it a little to just delete what text was already there.
Really appreciate it. thanks again
'*************** START OF CODE ***************
Dim ClickedOnceAlready As Boolean

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ClickedOnceAlready = False
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not ClickedOnceAlready Then
ClickedOnceAlready = True
With TextBox1
TextBox1.value = ""
End With
End If
End Sub
'*************** END OF CODE ***************
 
Top