Tabbing in Sub Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a main form with three sub-forms. I would like to tab from the main
form to the first sub-form then from the first sub-form to the second and
third. I can tab to the first sub-form easily, however when I tab in the
final field of the first sub-form it takes me back to the first field in that
form.

Any suggestions greatly appreciated.
 
First, subforms are usually in continuous form or datasheet view. Unless you
change the Cycle property of the subform, you'll go from the last field to
the next record of the subform. Once you reach the last field of the last
record, you'll go back to the first field of the last record.

What view are your subforms in? If they are in continuous form view, you
could add a button (it would appear on each record) that would set the focus
to the next subform. You would have this button be the last item in the tab
order. If you want to go to the next record, you would Tab twice, the first
tab would take you to the button and the next would take you to the next
record. If you wanted to go to the next subform you would Tab then Enter,
Tab would take you to the button and pressing Enter would execute the
button's Click event.

If you set the Cycle property (Other tab) of the subform to stay within the
current record, you could use the Exit event of the last control in the tab
order to set the focus to the next subform.

You could also use the Exit event of the subform control of the current
subform to set the focus as desired. Entering Ctrl+Tab will take you out of
the subform and back to the parent form. So, you would enter Ctrl+Tab to
leave the current subform and the subform control's Exit event would set the
focus to where you want.

The syntax to set the focus to the next subform using code located on the
current subform is:

Me.Parent.NameOfNextSubformControl.SetFocus
Me.Parent.NameOfNextSubformControl.Form.NameOfControlOnSubform.SetFocus

If you use the subform control's Exit event, that code will be executed by
the parent form, so leave out "Parent." in the lines above.

Yes, it is a two step process to set the focus to a control in a subform,
even if you aren't coming from another subform. You first have to set the
focus to the subform control on the parent form, then to the desired
control. Setting focus back to a control on the parent form is just a one
step operation.
 
Many thanks for your reply.

My sub-forms are in single form.

As I have very little experience with code buiders (practically none !) I
have used a macro in the final field at the On Exit event being: GoToControl;
Control Name and inserting the name of the next form here. This works well
and takes me to the next field in the next sub-form. When I get to the last
field of the last sub-form I have added GoToRecord Next along with the same
GoToControl. This works and takes me to the next record but when I close
down the whole form I get the message "You can't go to the specified record.
You may be at the end of a record set."
 
You may be using the GoToRecord Next at the last record, if so, there is no
next record to go to. Macros don't have error handlers to let you ignore
this, VBA does. If you close the form while the cursor is in one of the
boxes that you have set an Exit event for, the Exit event will fire before
the form closes.
 
Back
Top