Microsoft KB Archive/210011

= ACC2000: How to Move from Subform to Main Form by Using TAB or ENTER =

Article ID: 210011

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210011



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).



SUMMARY
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 file, FrmSmp00.mdb. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:

233324 ACC2000: Microsoft Access 2000 Sample Forms Available in Download Center

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



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.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

 Open the sample database Northwind.mdb. In the Database window, click Forms under Objects and open the Orders Subform form 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 DAO.Recordset Set RS = Me.RecordsetClone RS.MoveLast If StrComp(Me.Bookmark, rs.Bookmark, 0) = 0 Then Forms![Orders]![Freight].SetFocus 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 and close the Orders Subform. 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. Note 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.

<div class="references_section">