SpinButton control and focus

M

Matt Dalkie

Hi all,

I have a UserForm with a number of SpinButton controls which increase
or decrease the value in associated text boxes. Everything works
fine, but to tidy up the display a little, I want to make sure the
focus is changed to the text box, and not rest with the SipnButton.
Using the .SetFocus method appears to only work every other time the
SpinButton is changed. Is there something I'm missing here?

Code is as follows:

Sub SpinBn1_Change
With TextBx1
.Value = SpinBn1.Value
.SetFocus
End With
End Sub

Many thanks in advance

M@
 
J

Jim Rech

If you add a line of code to see where the focus is:

.SetFocus
Debug.Print UserForm1.ActiveControl.Name

you should see that the textbox does in fact have the focus when its value
changes (open the Debug window so you can see this). I think what's
happening is that the click on the spinner has not yet transferred focus to
the spinner at this point. You'll note that the click that fails is the one
that occurs when the textbox already has the focus. I don't know that you
can change this behavior though; I couldn't find a way.

--
Jim Rech
Excel MVP
| Hi all,
|
| I have a UserForm with a number of SpinButton controls which increase
| or decrease the value in associated text boxes. Everything works
| fine, but to tidy up the display a little, I want to make sure the
| focus is changed to the text box, and not rest with the SipnButton.
| Using the .SetFocus method appears to only work every other time the
| SpinButton is changed. Is there something I'm missing here?
|
| Code is as follows:
|
| Sub SpinBn1_Change
| With TextBx1
| .Value = SpinBn1.Value
| .SetFocus
| End With
| End Sub
|
| Many thanks in advance
|
| M@
 
M

Matt Dalkie

Hi Jim,

Thanks for the quick reply, and you put me onto a workaround...

Set the focus onto the spinbutton as the first line of the change
event. It works in terms of making the user interface tidy, until you
reach either the lower or upper limit, in which case, the focus stays
on the spinbutton.

M@
 

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