Lasse / Jacob,
I thought about this overnight and, together with Jonathan West's response
in a related post, think I've hit on a solution that doesn't rely on setting
the TabIndex of a particular control to 0 - which is actually a workable
solution and probably perfectly acceptable. However, if you want a bit more
control (and don't we all!) then something like this would probably work:
Assume a UserForm with a 3-page MultiPage control called "MultiPage1". On
Page1 there is (among other things) a TextBox called "TextBoxA" that is our
'target' TextBox, and similarly "TextBoxB" on Page2 and "TextBoxC" on Page3.
Sub MultiPage1_Change()
Select Case MultiPage1.Value
Case 1
If TextBoxA.Visible = True Then TextBoxA.SetFocus
Case 2
If TextBoxB.Visible = True Then TextBoxB.SetFocus
Case 3
If TextBoxC.Visible = True Then TextBoxC.SetFocus
End Select
End Sub
The check to see if the TextBox is visible is probably not absolutely
necessary since the only way the .Value property of the MultiPage control
could be a particular value is if the page containing the TextBox is
selected, which would (barring some other unforeseen circumstances)
automatically make the TextBox visible, but I never like to leave things to
chance and thus introduce an opportunity for error.
BTW, you could probably use a "sloppy" approach and eliminate the Select
Case statement entirely and just rely on checking the visibility of a
particular control in the MultiPage Change event, thusly:
Sub MultiPage1_Change()
If TextBoxA.Visible = True Then TextBoxA.SetFocus
If TextBoxB.Visible = True Then TextBoxB.SetFocus
If TextBoxC.Visible = True Then TextBoxC.SetFocus
End Sub
Or you could be slightly more elegant (but still just as "sloppy") and
retain the Select Case statement but modify what is being evaluated in it -
something like this:
Sub MultiPage1_Change()
Select Case True
Case TextBoxA.Visible
TextBoxA.SetFocus
Case TextBoxB.Visible
TextBoxB.SetFocus
Case TextBoxC.Visible
TextBoxC.SetFocus
End Select
End Sub
Many ways to skin this cat, but all rely on the MultiPage Change event. My
apologies for dismissing it so quickly before.
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.