Keeping focus on a txtbox

T

Tim

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?
 
D

dok112

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
 

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

Top