SetFocus to each page on a MultiPage control?

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
611
Office Version
  1. 2016
Platform
  1. Windows
Hello forum friends, I have a UserForm with a MultiPage control (7 pages or tabs) and I currently have Me.EstCPPTextBox1.SetFocus in my code which works fine. Trying to see if there is a simple way to have to the SetFocus move the cursor to the first textbox on any of the seven pages on the MultiForm if the user clicks on any one of the tabs?

Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Actually, I take that back. It's giving me a Run-time error '2110' - Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus. WTH?
 
Upvote 0
Try changing the TabIndex = 0 property of the textbox which for you is the first of every Page
 
Upvote 0
In my testing, it looks like when one changes the page on a multipage, the focus automatically moves to the first control in that page's Tab order.
If you change the tab order so your desired textboxes are first in their page's tab order, it should act as you want.
 
Upvote 0
I need to modify that observation, it is true only if there isn't a Click event for the multipage.
 
Upvote 0
@DanteAmor I did as you suggested and after adding the SetFocus back into the code, I am still getting the run-time error.
@mikerickson Let me know if you come up with anything.

Thanks guys!
 
Upvote 0
You must first select the page.
In the following example, first select page 0 (0 corresponds to the first page), which in my example is where the EstCPPTextBox1 is.
So if your EstCPPTextBox1 is on the second page, you must change 0 for 1.

VBA Code:
Private Sub CommandButton1_Click()
  MultiPage1.Value = 0
  Me.EstCPPTextBox1.SetFocus
End Sub
 
Upvote 0
@DanteAmor okay, so I added your code to the CommandButton that I use to open the form and that gives me a Compile error: Method or data member not found. So then I added it to the UserForm_Initialize() and it works without any errors. The cursor is in the EstCPPTextBox1 when I open the form but if I click on any of the other pages of the MultiPage control, there is no cursor in any of the TextBoxes, even though I set the TabIndex for the first textbox on all the pages to 0... any ideas?
 
Upvote 0
First, what I put is a simple example, so you can take it and apply it according to your needs.
Now, you can put your complete code here for your entire userform.

Me.EstCPPTextBox1.SetFocus
with this line we can only assume everything else.

Check this:
Select each page and check the taborder, at the top you should have a textbox, the textbox that for you is the first on the page, and I say for you, because we do not know what it is.

1590198838820.png



In my tests, if I put a textbox like tabindex 0 on every page, the cursor is shown on every page in the textbox
1590199287547.png
 
Upvote 0
If you want to set the focus to TextBox2 and you want to be sure it's ready to receive the focus
VBA Code:
With Me.TextBox2
    If TypeName(.Parent) = "Page" Then
        With .Parent
            .Parent.Value = .Index
        End With
    End If
    .SetFocus
End With

Another way to put a control at the top of its tab order is to set the .TabIndex to 0 in the Properties Window.
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

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