Text Box Clear User Instructions

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
365
How do I clear a text box of user instructions when they click in the text box or start entering into it.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Put your instructions in the TextBox as either the default or in the UserForm_Initialize event. Then put the following code for your TextBox:

Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X AS Single, VyVal Y As Single)

With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
End With
Selection.ClearContents
End Sub

Did that do the trick
 
Upvote 0
Excellent. How do I give focus to something else in the userform so the user has to click into it?
 
Upvote 0
After initialisation of the user form the cursor is in textbox1 ready to type. Unles the user moves the mouse down the prompt text in textbox1 is not selected and deleted. Thought the best way to deal with that is give something else on the user form the focus so the user has to move the cursor to the text box. Trouble is I haven't been able to find the function that gives an oject on the userform focus. I know it's in there somewhere.
 
Upvote 0
Got it thanks.
Public Started as Boolean

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
TextBox1.Tag = "Received"
If Started = False Then
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
End With
Selection.ClearContents
End If
Started = True
End Sub

and it's commandbutton1.setfocus

thanks for your help
 
Upvote 0
Wondered why the currently selected cell would mysteriously clear contents. The clear contents in the code above does more than clear the selection text in the text box.

best way to do above is:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
TextBox1.Tag = "Received"
If Started = False Then
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
End With
'Selection.ClearContents
TextBox1.EnterFieldBehavior = _
fmEnterFieldBehaviorRecallSelection
End If
Started = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top