Link to home
Start Free TrialLog in
Avatar of WMorrissey
WMorrissey

asked on

When entering new record or filtering to existing record, focus goes to 3rd tab instead of first

I have an Access form with a tab control -- five pages.  I have the standard "New" button -- here's the code:

If Me.Dirty Then RunCommand acCmdSaveRecord

DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl "ctl_clFacilityID"

I never have any problem with this in Access 2000, 2002 or 2003, but 2007 sends the focus to the first control on the third page, instead of the first control on the first page (ctl_clFacilityID).  This also happens when I filter the form based on a selection in a search screen.  

Any idea what I can look for?
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

do you have subforms in your tabs?
what is the name of the control that the focus is set to?
look for the Tab index value of that control. (0 ?)
Avatar of WMorrissey
WMorrissey

ASKER

Yes, there are subforms in the tabs, but on neither tab in question is a subform first in the tab order.  The tab index of the control that the focus is "wrongly" going to is 0, but so is the tab index of the control on the first page that the focus is supposed to go to.  

The page order in the tab control is correct -- I already checked that.

BTW, how do you get to the "View Tab Order" in Access 2007, where you can sort the controls in one place, rather than setting the tab index one control at a time?

(I hate the way they have to move everything around every other version -- and this is the worst!)
in a form, there can't be two controls having the same Tab Index.

how about changing this line
DoCmd.GoToControl "ctl_clFacilityID"

to

me.[ctl_clFacilityID].setfocus
Yes there can, if they are on two separate tabs.   If you create a new tab control and put one new control on each page, you'll see that they each have a 0 tab index.

I already tried ctl_clFacilityID.setfocus -- same result.
oh yes, you are right. i stand corrected.
No problem.  Any other ideas?
try

DoCmd.GoToRecord , , acNewRec
me.tabControlname.value=2

change tablcontrolname with actual name
also, if you haven't done so, do a compact and repair of your db.
one cause of this misbehaving of form is sign of corruption..
duh..
one cause of this misbehaving of form is corruption..
Nope -- nothing worked.
ASKER CERTIFIED SOLUTION
Avatar of WMorrissey
WMorrissey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the SendKeys "^{TAB}", True  move the focus out of the subform? is this correct or the focus is set to the next control in the subform?

It moves the focus out of the subform to the next control on the main form.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I changed it to

parent!controlname.setfocus

and moved the me.requery to after that line instead of before, and that seems to work.  The reason I had it the other way is that I wanted it to work even if I removed a control or changed the tab order.  But I can live with this.

Thanks for your help!
without seeing your db, it is IMPOSSIBLE for me to find where the problem is coming from... just a FYI