ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   First textbox in form not accepting input properly (https://www.excelbanter.com/excel-programming/312872-first-textbox-form-not-accepting-input-properly.html)

Jack

First textbox in form not accepting input properly
 
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?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

kkknie[_218_]

First textbox in form not accepting input properly
 

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



--
kkkni
-----------------------------------------------------------------------
kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754
View this thread: http://www.excelforum.com/showthread.php?threadid=26739


Geof Wyght[_2_]

First textbox in form not accepting input properly
 
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.
-----Original Message-----
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?




*** Sent via Developersdex http://www.developersdex.com

***
Don't just participate in USENET...get rewarded for it!
.


Geof

First textbox in form not accepting input properly
 
Way to go k!
-----Original Message-----

What is happening is that when you set the text box value

(I assume in
UserForm_Activate or UserForm_Initialize), it is acting

as if the value
was typed in (since it kind of was). To have it

highlighted, you must
highlight it:

Private Sub UserForm_Initialize()
TextBox1.Value = 12
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
End Sub

K


--
kkknie
----------------------------------------------------------

--------------
kkknie's Profile: http://www.excelforum.com/member.php?

action=getinfo&userid=7543
View this thread:

http://www.excelforum.com/showthread...hreadid=267397

.


Jack

First textbox in form not accepting input properly
 
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.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 03:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com