• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

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).
0
DavidWare
Asked:
DavidWare
  • 3
  • 2
1 Solution
 
DavidWareAuthor Commented:
Edited text of question.
0
 
brewdogCommented:
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:

me(strSubform).setfocus

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"
    Me(strSubform).SetFocus

Hope that helps . . .

brewdog
0
 
BrianWrenCommented:
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

  Me!<SubFormControlName>.Form!<SubsCtlName>.Setfocus

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

Brian
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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.

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

100 to each of you!
0
 
brewdogCommented:
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.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now