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

WMorrissey
WMorrissey used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
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 ?)

Author

Commented:
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.

Author

Commented:
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!)
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2016

Commented:
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

Author

Commented:
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.
Top Expert 2016

Commented:
oh yes, you are right. i stand corrected.

Author

Commented:
No problem.  Any other ideas?
Top Expert 2016

Commented:
try

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

change tablcontrolname with actual name
Top Expert 2016

Commented:
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..
Top Expert 2016

Commented:
duh..
one cause of this misbehaving of form is corruption..

Author

Commented:
Nope -- nothing worked.
I figured out what was causing the behavior.  Each of my subforms has code like the following, to allow the user to tab through the subforms just like any other control.  Apparently, Access 2007 can't handle this -- once I commented this code out of every subform, the problem vanished.  Does anyone know what the proper code would be in Access 2007?  (I don't want the user to have to pick up the mouse to exit a subform.)
 
Private Sub ctl_cdrIRRorCRR_Exit(Cancel As Integer)
On Error GoTo Err_ctl_cdrIRRorCRR_Exit

If IsNull(ctl_cdrIRRorCRR) Then
  Me.Requery
  SendKeys "^{TAB}", True
End If

Exit_ctl_cdrIRRorCRR_Exit:
    Exit Sub

Err_ctl_cdrIRRorCRR_Exit:
    MsgBox Err.Description
    Resume Exit_ctl_cdrIRRorCRR_Exit
   
End Sub

Top Expert 2016

Commented:
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?

Author

Commented:
It moves the focus out of the subform to the next control on the main form.
Top Expert 2016
Commented:
did you try replacing the sendkey line with

me.parent.setfocus

and if necessary add thie line too
me.parent.controlname.setfocus

Author

Commented:
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!
Top Expert 2016

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial