ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Keeping focus on a txtbox (https://www.excelbanter.com/excel-programming/358377-keeping-focus-txtbox.html)

Tim[_44_]

Keeping focus on a txtbox
 
I have a form with 2 controls; TextBox1 and SpinButton1. I want only
TextBox1 to ever have focus, and for SpinButton1 to do a small job,
then give focus back to TextBox1. The code I have written is as
follows:

Option Explicit
Private Sub SpinButton1_SpinDown()
TextBox1.SetFocus
End Sub
Private Sub SpinButton1_SpinUp()
TextBox1.SetFocus
End Sub

When I click SpinButton1, focus is sent to TextBox1 only every other
time; not every time. However, when I put a breakpoint on
TextBox1.SetFocus (so I have to click the 'run' arrow each time), focus
is returned to TextBox1 each time as it should be. Although tabstop
does not affect this effect, I do have it set to false. Setting
TakeFocusOnClick to false isn't a help, because a spin button doesn't
have that property, so I can't set it at all. I have placed a
'doevents' statement in each Sub, but that didn't help (Perhaps I
didn't do it correctly?).

How can I get it to return focus after each click to TextBox1?


dok112[_120_]

Keeping focus on a txtbox
 

heres the reply from your other thread. it's the same thing to be
done.

I dont have much experience with spinbuttons, but just as a little fun,
I tried to goof around with it. It's probably not 100% correct as far as
correct programming format, but it gets the job done, at least on my
system.

Add a SpinButton1.SetFocus command before the TextBox1.SetFocus
command. When you click on it, it doesnt depress like normal, but it
does reset the focus after only 1 click each time.

Option Explicit
Private Sub SpinButton1_SpinDown()
SpinButton1.SetFocus
TextBox1.SetFocus
End Sub
Private Sub SpinButton1_SpinUp()
SpinButton1.SetFocus
TextBox1.SetFocus
End Sub


--
dok112
------------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...o&userid=10581
View this thread: http://www.excelforum.com/showthread...hreadid=531110



All times are GMT +1. The time now is 09:46 AM.

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