Setting focus of any page in multipage Userform to TextBox 0

Pianostool

New Member
Joined
Dec 4, 2008
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hi folks, and thanks in advance.

I have a Multipage Userform with 9 tabs.

I have much the same layout for accepting data on each tab, so I've been able to set the first Textbox field on each page to have a Tab Index of 0.

I just want to have the cursor set focus to that Textbox on whatever tab the user selects, so it's ready to take data, saving them having to click in that field first on each tab.

What code do I add to achieve this, and where do I put it?

Thanks.
 
This is multipage with 3 tabs, each tab has textbox in it :

VBA Code:
Private Sub MultiPage1_Change()
    If MultiPage1.Value = 0 Then
        Me.TextBox1.SetFocus
    ElseIf MultiPage1.Value = 1 Then
        Me.TextBox2.SetFocus
    Else
        Me.TextBox3.SetFocus
    End If
End Sub

Put it on your MultiPage Change event.
 
Upvote 0
Solution
This is multipage with 3 tabs, each tab has textbox in it :

VBA Code:
Private Sub MultiPage1_Change()
    If MultiPage1.Value = 0 Then
        Me.TextBox1.SetFocus
    ElseIf MultiPage1.Value = 1 Then
        Me.TextBox2.SetFocus
    Else
        Me.TextBox3.SetFocus
    End If
End Sub

Put it on your MultiPage Change event.
Thanks LongToast, worked well. Legend!
 
Upvote 0
Setting the Tetxboxes TabIndex to 0 like you have done is enough.
Thanks Jaafar, I thought that should be enough too, but it just wasn't setting any focus either on launch or page change.
LongToast's code worked OK. Cheers.
 
Upvote 0
Hi

Appreciate you have a solution but another way to do what you want without the need for If Else construct would like this

VBA Code:
Private Sub MultiPage1_Change()
 Dim Page As Long
 Page = Me.MultiPage1.Value + 1
 Me.Controls("TextBox" & Choose(Page, 1, 2, 3, 4, 5, 6, 7, 8, 9)).SetFocus
End Sub

change the control name index values in the Choose function as required

You could though, with a little planning in your project, reduce this further by naming the textbox on each page in line with the multipage tab index value as follows

Page 0 TextBox0

Page 1 TextBox1

Page 2 TextBox2

And so on

Just be mindful the First Page of a MultiPage has a value of 0 (zero)

Then this single line of code should be all that is needed

VBA Code:
Private Sub MultiPage1_Change()
 Me.Controls("TextBox" & Me.MultiPage1.Value).SetFocus
End Sub

Both suggestions assume that your textbox controls retain their default naming convention.

Hope Helpful

Dave
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top