First textbox in form not accepting input properly

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

I have a form containing three textboxes with the right adjust property
set. The first textbox is initialized with the number 12. The cursor is
blinking behind the number 12, which is not highlighted like it should
be. When I type in the number 25 the textbox shows 1225 instead of
overwriting the number 12 to get 25. There is no problem when I type in
the remaining textboxes where the existing number is highlighted and is
overwritten by the number typed in.
I’ve tried making the tabindex 0 which didn’t work. I also put a dummy
textbox or commandbutton with an tabindex of 0 in front of the leading
textbox. This worked but its dumb having to have to tab it before
entering data in the desired textbox.

How can I fix this? What is happening? Is this a bug?
 
What is happening is that when you set the text box value (I assume i
UserForm_Activate or UserForm_Initialize), it is acting as if the valu
was typed in (since it kind of was). To have it highlighted, you mus
highlight it:

Private Sub UserForm_Initialize()
TextBox1.Value = 12
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
End Sub
 
I would guess this is by design. After all, if you have
initialized the value to 12, there must be a good reason
for it. Put it another way, if you wanted to change the
value as soon as the form opened, then why would you
initialize the text box to 12? The best I could do is this:
Private Sub UserForm_Initialize()
Me.TextBox1.Value = 12
Me.TextBox1.SelStart = 0
End Sub
Geof.
 
That did it. I'll admit I don't see why one has to go through those
extra steps but they work so lots of thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top