Textbox Default Value Not displaying During Userform Initialization; Selection Highlighting

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
With the code below, I am trying to highlight a default value of 000000 in a textbox (textbox1) in my userform. This will allow the user to overwrite the default entry without having to first select it.

Code:
        With TextBox1               'rental number
            'cb_mri.Visible = False
            .Locked = False
            .BackColor = RGB(255, 255, 255)
            .Value = format(0, "000000") 'new rental
            .SetFocus
            .SelStart = 0
            .SelLength = Len(.Text)
        End With

The default value of "000000" isn't showing in the textbox let along that value being highlighted.

Is anyone able to tell me where the problem exists?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Why do you believe you need to select the Textbox ?

Why not use a script like this:

Code:
Private Sub CommandButton2_Click()
'Modified  5/3/2019  9:52:30 PM  EDT
TextBox1.Value = "Cake"
End Sub
 
Upvote 0
Or if you want more then like this:

Code:
Private Sub CommandButton2_Click()
'Modified  5/3/2019  9:58:30 PM  EDT
With TextBox1
.Value = "Cake"
.BackColor = RGB(0, 255, 255)
End With
End Sub
 
Upvote 0
Hi My Answer Is This, thank you for your suggestions.

They would work, but they aren't providing the full feature of what my code is meant to do.

The purpose of selecting it, is that it will allow the user to overwrite the exisitng default value in the box. In your examples, the user will have to manually select the default text, deloete it, or overwite it. My code, which has worked in other instances, takes away the step of the user having to highlight (select) the text first on their own, it's done automatically. They can just type.

This concept ... but mine isn't working.
https://www.mrexcel.com/forum/excel-questions/211449-auto-highlight-text-textbox-userform.html
 
Last edited:
Upvote 0
What colour are you trying to make the textbox?
 
Upvote 0
Hi Fluff,

I'm trying to use a white background, with black font. I get a cursor in the middle of the textbox, but not a highlighted default value.
 
Upvote 0
I get 000000 in the textbox & that text is selected.
Try adding a new textbox (without changing any of the properties) & point the code to that textbox.
Does it work?
 
Upvote 0
Hi FLuff, thanks for your continued support.
As suggested, I created a new textbox and popinted that code to Textbox2. I got the same results. Blinking cursor ( | ) only.
 
Upvote 0
Is that code in the initialise event?
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

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