ACC: How to Move from Subform to Main Form by Using TAB or ENTER
ID: Q154893
|
The information in this article applies to:
-
Microsoft Access versions 2.0, 7.0, 97
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
This article demonstrates how you can press the TAB key or ENTER key to
move from the last control on the last record of a subform to a specified
control on the main form.
NOTE: This article explains a technique demonstrated in the sample
files, FrmSampl.exe (for Microsoft Access for Windows 95 version 7.0)
and FrmSmp97.exe (for Microsoft Access 97). For information about how
to obtain these sample files, please see the following articles in the
Microsoft Knowledge Base:
Q150895ACC95: Microsoft Access Sample Forms Available in Download Center
Q175066 ACC97: Microsoft Access 97 Sample Forms Available in Download Center
MORE INFORMATION
By default, Microsoft Access enables you to press the TAB key or ENTER key
to move the focus from one control to another control on a form, according
to the form's tab order. This includes moving to subform controls. However,
pressing the TAB or ENTER keys does not move the focus from a subform control back to the main form.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
NOTE: Visual Basic for Applications is called Access Basic in Microsoft
Access version 2.0. For more information about Access Basic, please refer
to the "Building Applications" manual.
CAUTION: Following the steps in this example will modify the sample
database Northwind.mdb (NWIND.MDB in version 2.0). You may want to back up
the Northwind.mdb (or NWIND.MDB) file, or perform these steps on a copy of
the Northwind database.
NOTE: In the example below, you can remove the line of code that uses the
Requery method of the subform control if you are using version 2.0. It is
there for compatibility with the form's Cycle property, which is a new
feature in version 7.0.
- Open the Northwind sample database.
- Click the Forms tab and open the Orders Subform in Design view.
- Set the OnExit property of the form's Discount control to the following
event procedure:
Private Sub Discount_Exit(Cancel As Integer)
On Error Goto Error_Routine
Dim RS As Recordset
Set RS = Me.RecordsetClone
RS.MoveLast
If StrComp(Me.Bookmark, rs.Bookmark, 0) = 0 Then
Forms![Orders]![Freight].SetFocus
' The following line may be removed in version 2.0
Forms![Orders]![Orders Subform].Requery
End If
Exit Sub
Error_Routine:
MsgBox "You must be on a record with data"
Exit Sub
End Sub
- Save the Orders Subform and close it.
- Open the Orders form in Form view and press the TAB key or the ENTER key
to move from one control to the next on the form. Notice that the form's
Freight control receives the focus when you press TAB or ENTER from the
Discount control of the last record displayed on the subform.
REFERENCES
For more information about setting a form's tab order, search for tab
order in forms, and then Change tab order in a form using the Microsoft
Access 97 Help Index.
For more information about the Bookmark property, search on the phrase
Bookmark, and then view "Bookmark Property (Microsoft Access)" using the
Microsoft Access for Windows 97 Help Index.
Additional query words:
navigate programmatically
Keywords : kbusage FmsSubf FmsHowto
Version : WINDOWS:2.0,7.0,97
Platform : WINDOWS
Issue type : kbhowto