problem with focus of spinbutton

E

Edwin Verwer

I have a userform with a spinbutton and a textbox.
Every time i press the spinbutton focus is set to the spinbox and little
squares apear in the up and down buttons of the spinbutton.
I want to set the focus back to the textbox so that those squares aren't
there anymore.

I have used the following code:

-----------------------------------------------
Private Sub spinbutton_SpinDown()

If userform.textbox.Value <> 1 Then userform.textbox.Value =
userform.textbox.Value - 1

End Sub

Private Sub spinbutton_SpinUp()

userform.textbox.Value = userform.textbox.Value + 1

end sub

--------------------------------------------------

I have already tried putting the code.
userform.textbox.setfocus at the end of the spinup and spindown effent.
but then the first time i press the spinbutton he wil set focus to the
spinbutton the next time the focus wil be put to the textbox and so the focus
switches everytime.

Is there a way to simply set focus to the textbox after he is done raising
the value of the textbox?
 
D

Doug Robbins - Word MVP

Nearest I can come it to add a command to set the focus back to the text
box. Then, the focus is on the text box and the squares are not shown for
every other click of the spin button.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
K

Kevin Vanderwater

I ran into this same problem and solved it by adding a SetFocus to the
spinbutton at the beginning of the SpinUp and SpinDown routines AND adding
the SetFocus to the textbox as the end of the routines... Now the focus
isn't left on the spinbutton control...

Enjoy!

Private Sub spinbutton_SpinDown()
userform.spinbutton.SetFocus
If userform.textbox.Value <> 1 Then userform.textbox.Value =
userform.textbox.Value - 1
userform.textbox.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