Tab order between subforms on a main form....

  • Thread starter Thread starter mattieflo
  • Start date Start date
M

mattieflo

Hello,

Does anyone know where I would find a good resource on tab order? I
understand how to set tab order on one form but it gets tricky when I'm
trying to tab correctly from one subform to another subform.
 
Hello,

Does anyone know where I would find a good resource on tab order? I
understand how to set tab order on one form but it gets tricky when I'm
trying to tab correctly from one subform to another subform.

The usual problem in this situation is that once you tab into a subform, just
hitting tab will keep you in the subform - on the same record if the Cycle
property is set to same record, or to a new record on the subform if it's set
to All Records.

You can tab out of the subform to the next control in the parent form's tab
order by typing Ctrl-Tab. If the next control is another subform... well,
there you are.

You can also put an unbound control last in the first subform's tab order. Put
it behind some other control and/or make it one twip square so that it's not
going to be hit with the mouse; in its GotFocus event you can put code like

Private Sub txtRelay_GotFocus()
Parent.SetFocus
Parent.Subform2.SetFocus
Parent.Subform2.Form!controlname.SetFocus
End Sub

to explicitly move to a chosen control in subform2.

John W. Vinson [MVP]
 
Great idea, thanks for the suggestion.

Just a quick question....is there a reason I can't set the focus to the 2nd
subform on the on exit event of the last control in subform 1?
 
Great idea, thanks for the suggestion.

Just a quick question....is there a reason I can't set the focus to the 2nd
subform on the on exit event of the last control in subform 1?

You can't be certain that the user will ever even set focus to that control...
much less exit it. Otherwise, it's worth a try.

John W. Vinson [MVP]
 
If you do it with the on exit procedure remember that users also use a mouse.

When focus is on the last control of the subform and user clicks another control (say a tabpage,or a button) the on exit event will still be triggered and focus will not be put on the control the user clicked.

The solution with a dummy control is a better one.
Also you can more easily shift or add controls to the form without breaking code, cause dummy remains last control in tab order
 
'EXAMPLE CODE FOR SINGLE RECORD FORM
'---------------------------
Private Sub LEAVESUBFORMDUMMY_GotFocus()
'When we enter subform next time whe don't want LEAVESUBFORM_GotFocus to get triggered
'As focussed control of a subform is remembered - so we set focus on first tab element of subform
Me.[First tab control].SetFocus
'Now whe do the actual Focus moving
Parent.SetFocus
Parent.subform2.SetFocus
Parent.subform2![First tab control of header].SetFocus
End Sub

'FROM FORM HEADER TO ACTUAL RECORDS
'----------------------------------
Private Sub LEAVEFORMHEADER_GotFocus()
Me![First tab control of record].SetFocus
End Sub

Private Sub LEAVESUBFORM_GotFocus()
On Error GoTo Error_Routine

With Recordset
If .AbsolutePosition >= .RecordCount - 1 Then
Me![First tab control of header].SetFocus
Parent.SetFocus
Parent.[First tab control].SetFocus
End If

End With
Exit Sub
Error_Routine:

'Do error thingies e.g. Call LogError(...)
Exit Sub

End Sub
 
Back
Top