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

ID: Q210011


The information in this article applies to:
  • Microsoft Access 2000

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. Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


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: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform 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 need to reference the Microsoft DAO 3.6 Object Library.

  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:


  4. 
    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 
  5. Save and close the Orders Subform.


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



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.

Additional query words: navigate programmatically

Keywords : kbusage kbdta AccCon FmsSubf FmsHowto
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.