Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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).

↑ Back to the top


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.

↑ Back to the top


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.

  1. Open the sample database Northwind.mdb.
  2. In the Database window, click Forms under Objects and open the Orders Subform form in Design view.
  3. 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
    					
  4. Save and close the Orders Subform.
  5. 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.

↑ Back to the top


References

For more information about setting a form's tab order, click Microsoft Access Help on the Help menu, type tab order in forms in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about the Bookmark property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Bookmark in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB210011, kbusage, kbprogramming, kbofficeprog, kbinfo, kbdta

↑ Back to the top

Article Info
Article ID : 210011
Revision : 5
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 408