SetFocus from Form to Tab Control's subform

How can I send the focus from a Textbox on the Main Form to a Textbox on the Active Tab Sheet's subform?

I have a Form called frmEmployee.

On the top of frmEmployee, I have 3 Textboxes (txtName, txtID, txtClock).

Below those Textboxes, I have a Tab Control (tabctlEmp) with 7 Sheets (tabPersonal, tabAttendance, tabInsurance...etc.).

Each Tab Sheet contains one subform (tabPersonal has [PER subform], ...etc) looking at different tables.

On each of those subforms, there are Textboxes ([PER subform] has txtAddress,... etc).

I want to set the Tab Order to leave the txtClock Textbox on frmEmployee and go to the first Textbox on the Active Tab Sheet's subform.

I put code in the txtClock Textbox's "OnExit" event to set the focus to the Tab Control, but it always goes to the first Tab Sheet.  I want to have the focus go to the first Textbox on the Currently Visible Tab Sheet, but I don't know how to identify the Tab Control's "Active TabSheet" Property (if there is something like that).
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DavidWareAuthor Commented:
Edited text of question.
You don't actually need to go through the tab control to get to the subform. I believe this line would do it if you were hard-coding:

me![PER subform]![txtAddress].SetFocus

to generic it, I would probably set a variable in the form's general declarations, something like:

dim strSubform as string

Then, on the Change event of the tab control, I'd evaluate which tab was chosen and set strSubform to the subform on the current tab page. Then the line above would look like:


I just tried this, and it worked very well. By setting the focus to the subform itself, you'll be putting the cursor in the first available text box on that subform. One other thing I had to change: if the user hasn't clicked on any tab pages, you'll need to put in a default for strSubform. Here's my code:

    If strSubform = "" Then strSubform = "YourDefaultSubform"

Hope that helps . . .


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tabs each have a Page Index.

The current page is ascertained by the value of the control itself, which is equal to the index of the page that's active.  If your control is called ctlTab, and page 2 has an index of 8, and is the current page, then

   MsgBox "Tab control = " & Me!ctlTab

will present:  Tab control = 8

The way to address a subform on a tab control is


You do not need to mention the tab contorl in refering to the subform--it belongs to the main form, not the tab control.

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

DavidWareAuthor Commented:
brewdog and BrianWren,

I used both of your comments to solve this, so allow me to split the points.

Thank you both for your help.

I will award this question for 50 to brewdog and post another 50 pt. question for BrianWren.

Hope that is Ok.

DavidWareAuthor Commented:
Doesn't let me do it, so I will go ahead and do the right thing.

100 to each of you!
Excellent. Glad we could help you out, DavidWare. If you haven't already posted the other question for Brian and you want to save the 100 points, let me know and I'll post a 50-pointer for him.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.