How to set focus on a tab on a userform?

Brad24

Board Regular
Joined
May 4, 2015
Messages
81
Hi, I have a user form that has tabs on it.

When I click a button to open the form, I then initialize the form. I have CustomerName.SetFocus which is the first textbox on the first tab. I have found a bug where if the user is on the forth tab for example and closes the application, it will error when reopening with the "Can't move focus to the control because it is invisible..."

It is looking for this CustomerName textbox which is over on the first tab. Is it possible when this form tries to initialize when I click the button to open the form, that it automatically sends the user to the first tab every time, and then it will find that textbox?

Or is there code that can tell what tab the user is on(the current state of the form), and then I could put an if statement in that says depending on what tab you are on, set focus to that tabs textbox instead?

Thanks in advance.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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